11cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/codegen/assembler-inl.h"
61cb0ef41Sopenharmony_ci#include "src/common/globals.h"
71cb0ef41Sopenharmony_ci#include "src/date/date.h"
81cb0ef41Sopenharmony_ci#include "src/diagnostics/disasm.h"
91cb0ef41Sopenharmony_ci#include "src/diagnostics/disassembler.h"
101cb0ef41Sopenharmony_ci#include "src/heap/combined-heap.h"
111cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier-inl.h"
121cb0ef41Sopenharmony_ci#include "src/heap/read-only-heap.h"
131cb0ef41Sopenharmony_ci#include "src/ic/handler-configuration-inl.h"
141cb0ef41Sopenharmony_ci#include "src/init/bootstrapper.h"
151cb0ef41Sopenharmony_ci#include "src/logging/runtime-call-stats-scope.h"
161cb0ef41Sopenharmony_ci#include "src/objects/allocation-site-inl.h"
171cb0ef41Sopenharmony_ci#include "src/objects/arguments-inl.h"
181cb0ef41Sopenharmony_ci#include "src/objects/bigint.h"
191cb0ef41Sopenharmony_ci#include "src/objects/call-site-info-inl.h"
201cb0ef41Sopenharmony_ci#include "src/objects/cell-inl.h"
211cb0ef41Sopenharmony_ci#include "src/objects/data-handler-inl.h"
221cb0ef41Sopenharmony_ci#include "src/objects/debug-objects-inl.h"
231cb0ef41Sopenharmony_ci#include "src/objects/elements.h"
241cb0ef41Sopenharmony_ci#include "src/objects/embedder-data-array-inl.h"
251cb0ef41Sopenharmony_ci#include "src/objects/embedder-data-slot-inl.h"
261cb0ef41Sopenharmony_ci#include "src/objects/feedback-cell-inl.h"
271cb0ef41Sopenharmony_ci#include "src/objects/field-type.h"
281cb0ef41Sopenharmony_ci#include "src/objects/foreign-inl.h"
291cb0ef41Sopenharmony_ci#include "src/objects/free-space-inl.h"
301cb0ef41Sopenharmony_ci#include "src/objects/function-kind.h"
311cb0ef41Sopenharmony_ci#include "src/objects/hash-table-inl.h"
321cb0ef41Sopenharmony_ci#include "src/objects/instance-type.h"
331cb0ef41Sopenharmony_ci#include "src/objects/js-array-buffer-inl.h"
341cb0ef41Sopenharmony_ci#include "src/objects/js-array-inl.h"
351cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
361cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
371cb0ef41Sopenharmony_ci#include "src/objects/turbofan-types-inl.h"
381cb0ef41Sopenharmony_ci#include "src/roots/roots.h"
391cb0ef41Sopenharmony_ci#ifdef V8_INTL_SUPPORT
401cb0ef41Sopenharmony_ci#include "src/objects/js-break-iterator-inl.h"
411cb0ef41Sopenharmony_ci#include "src/objects/js-collator-inl.h"
421cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
431cb0ef41Sopenharmony_ci#include "src/objects/js-collection-inl.h"
441cb0ef41Sopenharmony_ci#ifdef V8_INTL_SUPPORT
451cb0ef41Sopenharmony_ci#include "src/objects/js-date-time-format-inl.h"
461cb0ef41Sopenharmony_ci#include "src/objects/js-display-names-inl.h"
471cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
481cb0ef41Sopenharmony_ci#include "src/objects/js-generator-inl.h"
491cb0ef41Sopenharmony_ci#ifdef V8_INTL_SUPPORT
501cb0ef41Sopenharmony_ci#include "src/objects/js-list-format-inl.h"
511cb0ef41Sopenharmony_ci#include "src/objects/js-locale-inl.h"
521cb0ef41Sopenharmony_ci#include "src/objects/js-number-format-inl.h"
531cb0ef41Sopenharmony_ci#include "src/objects/js-plural-rules-inl.h"
541cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
551cb0ef41Sopenharmony_ci#include "src/objects/js-regexp-inl.h"
561cb0ef41Sopenharmony_ci#include "src/objects/js-regexp-string-iterator-inl.h"
571cb0ef41Sopenharmony_ci#include "src/objects/js-shadow-realms-inl.h"
581cb0ef41Sopenharmony_ci#ifdef V8_INTL_SUPPORT
591cb0ef41Sopenharmony_ci#include "src/objects/js-relative-time-format-inl.h"
601cb0ef41Sopenharmony_ci#include "src/objects/js-segment-iterator-inl.h"
611cb0ef41Sopenharmony_ci#include "src/objects/js-segmenter-inl.h"
621cb0ef41Sopenharmony_ci#include "src/objects/js-segments-inl.h"
631cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
641cb0ef41Sopenharmony_ci#include "src/objects/js-struct-inl.h"
651cb0ef41Sopenharmony_ci#include "src/objects/js-temporal-objects-inl.h"
661cb0ef41Sopenharmony_ci#include "src/objects/js-weak-refs-inl.h"
671cb0ef41Sopenharmony_ci#include "src/objects/literal-objects-inl.h"
681cb0ef41Sopenharmony_ci#include "src/objects/maybe-object.h"
691cb0ef41Sopenharmony_ci#include "src/objects/megadom-handler-inl.h"
701cb0ef41Sopenharmony_ci#include "src/objects/microtask-inl.h"
711cb0ef41Sopenharmony_ci#include "src/objects/module-inl.h"
721cb0ef41Sopenharmony_ci#include "src/objects/oddball-inl.h"
731cb0ef41Sopenharmony_ci#include "src/objects/promise-inl.h"
741cb0ef41Sopenharmony_ci#include "src/objects/property-descriptor-object-inl.h"
751cb0ef41Sopenharmony_ci#include "src/objects/struct-inl.h"
761cb0ef41Sopenharmony_ci#include "src/objects/swiss-name-dictionary-inl.h"
771cb0ef41Sopenharmony_ci#include "src/objects/synthetic-module-inl.h"
781cb0ef41Sopenharmony_ci#include "src/objects/template-objects-inl.h"
791cb0ef41Sopenharmony_ci#include "src/objects/torque-defined-classes-inl.h"
801cb0ef41Sopenharmony_ci#include "src/objects/transitions-inl.h"
811cb0ef41Sopenharmony_ci#include "src/regexp/regexp.h"
821cb0ef41Sopenharmony_ci#include "src/utils/ostreams.h"
831cb0ef41Sopenharmony_ci#include "torque-generated/class-verifiers.h"
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
861cb0ef41Sopenharmony_ci#include "src/base/strings.h"
871cb0ef41Sopenharmony_ci#include "src/debug/debug-wasm-objects-inl.h"
881cb0ef41Sopenharmony_ci#include "src/wasm/wasm-objects-inl.h"
891cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_cinamespace v8 {
921cb0ef41Sopenharmony_cinamespace internal {
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci// Heap Verification Overview
951cb0ef41Sopenharmony_ci// --------------------------
961cb0ef41Sopenharmony_ci// - Each InstanceType has a separate XXXVerify method which checks an object's
971cb0ef41Sopenharmony_ci//   integrity in isolation.
981cb0ef41Sopenharmony_ci// - --verify-heap will iterate over all gc spaces and call ObjectVerify() on
991cb0ef41Sopenharmony_ci//   every encountered tagged pointer.
1001cb0ef41Sopenharmony_ci// - Verification should be pushed down to the specific instance type if its
1011cb0ef41Sopenharmony_ci//   integrity is independent of an outer object.
1021cb0ef41Sopenharmony_ci// - In cases where the InstanceType is too generic (e.g. FixedArray) the
1031cb0ef41Sopenharmony_ci//   XXXVerify of the outer method has to do recursive verification.
1041cb0ef41Sopenharmony_ci// - If the corresponding objects have inheritence the parent's Verify method
1051cb0ef41Sopenharmony_ci//   is called as well.
1061cb0ef41Sopenharmony_ci// - For any field containing pointes VerifyPointer(...) should be called.
1071cb0ef41Sopenharmony_ci//
1081cb0ef41Sopenharmony_ci// Caveats
1091cb0ef41Sopenharmony_ci// -------
1101cb0ef41Sopenharmony_ci// - Assume that any of the verify methods is incomplete!
1111cb0ef41Sopenharmony_ci// - Some integrity checks are only partially done due to objects being in
1121cb0ef41Sopenharmony_ci//   partially initialized states when a gc happens, for instance when outer
1131cb0ef41Sopenharmony_ci//   objects are allocted before inner ones.
1141cb0ef41Sopenharmony_ci//
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci#ifdef VERIFY_HEAP
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci#define USE_TORQUE_VERIFIER(Class)                                \
1191cb0ef41Sopenharmony_ci  void Class::Class##Verify(Isolate* isolate) {                   \
1201cb0ef41Sopenharmony_ci    TorqueGeneratedClassVerifiers::Class##Verify(*this, isolate); \
1211cb0ef41Sopenharmony_ci  }
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_civoid Object::ObjectVerify(Isolate* isolate) {
1241cb0ef41Sopenharmony_ci  RCS_SCOPE(isolate, RuntimeCallCounterId::kObjectVerify);
1251cb0ef41Sopenharmony_ci  if (IsSmi()) {
1261cb0ef41Sopenharmony_ci    Smi::cast(*this).SmiVerify(isolate);
1271cb0ef41Sopenharmony_ci  } else {
1281cb0ef41Sopenharmony_ci    HeapObject::cast(*this).HeapObjectVerify(isolate);
1291cb0ef41Sopenharmony_ci  }
1301cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base(isolate);
1311cb0ef41Sopenharmony_ci  CHECK(!IsConstructor(cage_base) || IsCallable(cage_base));
1321cb0ef41Sopenharmony_ci}
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_civoid Object::VerifyPointer(Isolate* isolate, Object p) {
1351cb0ef41Sopenharmony_ci  if (p.IsHeapObject()) {
1361cb0ef41Sopenharmony_ci    HeapObject::VerifyHeapPointer(isolate, p);
1371cb0ef41Sopenharmony_ci  } else {
1381cb0ef41Sopenharmony_ci    CHECK(p.IsSmi());
1391cb0ef41Sopenharmony_ci  }
1401cb0ef41Sopenharmony_ci}
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_civoid Object::VerifyAnyTagged(Isolate* isolate, Object p) {
1431cb0ef41Sopenharmony_ci  if (p.IsHeapObject()) {
1441cb0ef41Sopenharmony_ci    if (V8_EXTERNAL_CODE_SPACE_BOOL) {
1451cb0ef41Sopenharmony_ci      CHECK(IsValidHeapObject(isolate->heap(), HeapObject::cast(p)));
1461cb0ef41Sopenharmony_ci    } else {
1471cb0ef41Sopenharmony_ci      HeapObject::VerifyHeapPointer(isolate, p);
1481cb0ef41Sopenharmony_ci    }
1491cb0ef41Sopenharmony_ci  } else {
1501cb0ef41Sopenharmony_ci    CHECK(p.IsSmi());
1511cb0ef41Sopenharmony_ci  }
1521cb0ef41Sopenharmony_ci}
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_civoid MaybeObject::VerifyMaybeObjectPointer(Isolate* isolate, MaybeObject p) {
1551cb0ef41Sopenharmony_ci  HeapObject heap_object;
1561cb0ef41Sopenharmony_ci  if (p->GetHeapObject(&heap_object)) {
1571cb0ef41Sopenharmony_ci    HeapObject::VerifyHeapPointer(isolate, heap_object);
1581cb0ef41Sopenharmony_ci  } else {
1591cb0ef41Sopenharmony_ci    CHECK(p->IsSmi() || p->IsCleared() || MapWord::IsPacked(p->ptr()));
1601cb0ef41Sopenharmony_ci  }
1611cb0ef41Sopenharmony_ci}
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_civoid Smi::SmiVerify(Isolate* isolate) {
1641cb0ef41Sopenharmony_ci  CHECK(IsSmi());
1651cb0ef41Sopenharmony_ci  CHECK(!IsCallable());
1661cb0ef41Sopenharmony_ci  CHECK(!IsConstructor());
1671cb0ef41Sopenharmony_ci}
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_civoid TaggedIndex::TaggedIndexVerify(Isolate* isolate) {
1701cb0ef41Sopenharmony_ci  CHECK(IsTaggedIndex());
1711cb0ef41Sopenharmony_ci}
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_civoid HeapObject::HeapObjectVerify(Isolate* isolate) {
1741cb0ef41Sopenharmony_ci  CHECK(IsHeapObject());
1751cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base(isolate);
1761cb0ef41Sopenharmony_ci  VerifyPointer(isolate, map(cage_base));
1771cb0ef41Sopenharmony_ci  CHECK(map(cage_base).IsMap(cage_base));
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ci  switch (map(cage_base).instance_type()) {
1801cb0ef41Sopenharmony_ci#define STRING_TYPE_CASE(TYPE, size, name, CamelName) case TYPE:
1811cb0ef41Sopenharmony_ci    STRING_TYPE_LIST(STRING_TYPE_CASE)
1821cb0ef41Sopenharmony_ci#undef STRING_TYPE_CASE
1831cb0ef41Sopenharmony_ci    if (IsConsString(cage_base)) {
1841cb0ef41Sopenharmony_ci      ConsString::cast(*this).ConsStringVerify(isolate);
1851cb0ef41Sopenharmony_ci    } else if (IsSlicedString(cage_base)) {
1861cb0ef41Sopenharmony_ci      SlicedString::cast(*this).SlicedStringVerify(isolate);
1871cb0ef41Sopenharmony_ci    } else if (IsThinString(cage_base)) {
1881cb0ef41Sopenharmony_ci      ThinString::cast(*this).ThinStringVerify(isolate);
1891cb0ef41Sopenharmony_ci    } else if (IsSeqString(cage_base)) {
1901cb0ef41Sopenharmony_ci      SeqString::cast(*this).SeqStringVerify(isolate);
1911cb0ef41Sopenharmony_ci    } else if (IsExternalString(cage_base)) {
1921cb0ef41Sopenharmony_ci      ExternalString::cast(*this).ExternalStringVerify(isolate);
1931cb0ef41Sopenharmony_ci    } else {
1941cb0ef41Sopenharmony_ci      String::cast(*this).StringVerify(isolate);
1951cb0ef41Sopenharmony_ci    }
1961cb0ef41Sopenharmony_ci    break;
1971cb0ef41Sopenharmony_ci    case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:
1981cb0ef41Sopenharmony_ci      ObjectBoilerplateDescription::cast(*this)
1991cb0ef41Sopenharmony_ci          .ObjectBoilerplateDescriptionVerify(isolate);
2001cb0ef41Sopenharmony_ci      break;
2011cb0ef41Sopenharmony_ci    // FixedArray types
2021cb0ef41Sopenharmony_ci    case CLOSURE_FEEDBACK_CELL_ARRAY_TYPE:
2031cb0ef41Sopenharmony_ci    case HASH_TABLE_TYPE:
2041cb0ef41Sopenharmony_ci    case ORDERED_HASH_MAP_TYPE:
2051cb0ef41Sopenharmony_ci    case ORDERED_HASH_SET_TYPE:
2061cb0ef41Sopenharmony_ci    case ORDERED_NAME_DICTIONARY_TYPE:
2071cb0ef41Sopenharmony_ci    case NAME_TO_INDEX_HASH_TABLE_TYPE:
2081cb0ef41Sopenharmony_ci    case REGISTERED_SYMBOL_TABLE_TYPE:
2091cb0ef41Sopenharmony_ci    case NAME_DICTIONARY_TYPE:
2101cb0ef41Sopenharmony_ci    case GLOBAL_DICTIONARY_TYPE:
2111cb0ef41Sopenharmony_ci    case NUMBER_DICTIONARY_TYPE:
2121cb0ef41Sopenharmony_ci    case SIMPLE_NUMBER_DICTIONARY_TYPE:
2131cb0ef41Sopenharmony_ci    case EPHEMERON_HASH_TABLE_TYPE:
2141cb0ef41Sopenharmony_ci    case SCRIPT_CONTEXT_TABLE_TYPE:
2151cb0ef41Sopenharmony_ci      FixedArray::cast(*this).FixedArrayVerify(isolate);
2161cb0ef41Sopenharmony_ci      break;
2171cb0ef41Sopenharmony_ci    case AWAIT_CONTEXT_TYPE:
2181cb0ef41Sopenharmony_ci    case BLOCK_CONTEXT_TYPE:
2191cb0ef41Sopenharmony_ci    case CATCH_CONTEXT_TYPE:
2201cb0ef41Sopenharmony_ci    case DEBUG_EVALUATE_CONTEXT_TYPE:
2211cb0ef41Sopenharmony_ci    case EVAL_CONTEXT_TYPE:
2221cb0ef41Sopenharmony_ci    case FUNCTION_CONTEXT_TYPE:
2231cb0ef41Sopenharmony_ci    case MODULE_CONTEXT_TYPE:
2241cb0ef41Sopenharmony_ci    case SCRIPT_CONTEXT_TYPE:
2251cb0ef41Sopenharmony_ci    case WITH_CONTEXT_TYPE:
2261cb0ef41Sopenharmony_ci      Context::cast(*this).ContextVerify(isolate);
2271cb0ef41Sopenharmony_ci      break;
2281cb0ef41Sopenharmony_ci    case NATIVE_CONTEXT_TYPE:
2291cb0ef41Sopenharmony_ci      NativeContext::cast(*this).NativeContextVerify(isolate);
2301cb0ef41Sopenharmony_ci      break;
2311cb0ef41Sopenharmony_ci    case FEEDBACK_METADATA_TYPE:
2321cb0ef41Sopenharmony_ci      FeedbackMetadata::cast(*this).FeedbackMetadataVerify(isolate);
2331cb0ef41Sopenharmony_ci      break;
2341cb0ef41Sopenharmony_ci    case TRANSITION_ARRAY_TYPE:
2351cb0ef41Sopenharmony_ci      TransitionArray::cast(*this).TransitionArrayVerify(isolate);
2361cb0ef41Sopenharmony_ci      break;
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci    case CODE_TYPE:
2391cb0ef41Sopenharmony_ci      Code::cast(*this).CodeVerify(isolate);
2401cb0ef41Sopenharmony_ci      break;
2411cb0ef41Sopenharmony_ci    case JS_API_OBJECT_TYPE:
2421cb0ef41Sopenharmony_ci    case JS_ARRAY_ITERATOR_PROTOTYPE_TYPE:
2431cb0ef41Sopenharmony_ci    case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
2441cb0ef41Sopenharmony_ci    case JS_ERROR_TYPE:
2451cb0ef41Sopenharmony_ci    case JS_ITERATOR_PROTOTYPE_TYPE:
2461cb0ef41Sopenharmony_ci    case JS_MAP_ITERATOR_PROTOTYPE_TYPE:
2471cb0ef41Sopenharmony_ci    case JS_OBJECT_PROTOTYPE_TYPE:
2481cb0ef41Sopenharmony_ci    case JS_PROMISE_PROTOTYPE_TYPE:
2491cb0ef41Sopenharmony_ci    case JS_REG_EXP_PROTOTYPE_TYPE:
2501cb0ef41Sopenharmony_ci    case JS_SET_ITERATOR_PROTOTYPE_TYPE:
2511cb0ef41Sopenharmony_ci    case JS_SET_PROTOTYPE_TYPE:
2521cb0ef41Sopenharmony_ci    case JS_SPECIAL_API_OBJECT_TYPE:
2531cb0ef41Sopenharmony_ci    case JS_STRING_ITERATOR_PROTOTYPE_TYPE:
2541cb0ef41Sopenharmony_ci    case JS_TYPED_ARRAY_PROTOTYPE_TYPE:
2551cb0ef41Sopenharmony_ci      JSObject::cast(*this).JSObjectVerify(isolate);
2561cb0ef41Sopenharmony_ci      break;
2571cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
2581cb0ef41Sopenharmony_ci    case WASM_INSTANCE_OBJECT_TYPE:
2591cb0ef41Sopenharmony_ci      WasmInstanceObject::cast(*this).WasmInstanceObjectVerify(isolate);
2601cb0ef41Sopenharmony_ci      break;
2611cb0ef41Sopenharmony_ci    case WASM_VALUE_OBJECT_TYPE:
2621cb0ef41Sopenharmony_ci      WasmValueObject::cast(*this).WasmValueObjectVerify(isolate);
2631cb0ef41Sopenharmony_ci      break;
2641cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
2651cb0ef41Sopenharmony_ci    case JS_SET_KEY_VALUE_ITERATOR_TYPE:
2661cb0ef41Sopenharmony_ci    case JS_SET_VALUE_ITERATOR_TYPE:
2671cb0ef41Sopenharmony_ci      JSSetIterator::cast(*this).JSSetIteratorVerify(isolate);
2681cb0ef41Sopenharmony_ci      break;
2691cb0ef41Sopenharmony_ci    case JS_MAP_KEY_ITERATOR_TYPE:
2701cb0ef41Sopenharmony_ci    case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
2711cb0ef41Sopenharmony_ci    case JS_MAP_VALUE_ITERATOR_TYPE:
2721cb0ef41Sopenharmony_ci      JSMapIterator::cast(*this).JSMapIteratorVerify(isolate);
2731cb0ef41Sopenharmony_ci      break;
2741cb0ef41Sopenharmony_ci    case FILLER_TYPE:
2751cb0ef41Sopenharmony_ci      break;
2761cb0ef41Sopenharmony_ci    case CODE_DATA_CONTAINER_TYPE:
2771cb0ef41Sopenharmony_ci      CodeDataContainer::cast(*this).CodeDataContainerVerify(isolate);
2781cb0ef41Sopenharmony_ci      break;
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci#define MAKE_TORQUE_CASE(Name, TYPE)         \
2811cb0ef41Sopenharmony_ci  case TYPE:                                 \
2821cb0ef41Sopenharmony_ci    Name::cast(*this).Name##Verify(isolate); \
2831cb0ef41Sopenharmony_ci    break;
2841cb0ef41Sopenharmony_ci      // Every class that has its fields defined in a .tq file and corresponds
2851cb0ef41Sopenharmony_ci      // to exactly one InstanceType value is included in the following list.
2861cb0ef41Sopenharmony_ci      TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED(MAKE_TORQUE_CASE)
2871cb0ef41Sopenharmony_ci      TORQUE_INSTANCE_CHECKERS_MULTIPLE_FULLY_DEFINED(MAKE_TORQUE_CASE)
2881cb0ef41Sopenharmony_ci#undef MAKE_TORQUE_CASE
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci    case ALLOCATION_SITE_TYPE:
2911cb0ef41Sopenharmony_ci      AllocationSite::cast(*this).AllocationSiteVerify(isolate);
2921cb0ef41Sopenharmony_ci      break;
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci    case LOAD_HANDLER_TYPE:
2951cb0ef41Sopenharmony_ci      LoadHandler::cast(*this).LoadHandlerVerify(isolate);
2961cb0ef41Sopenharmony_ci      break;
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci    case STORE_HANDLER_TYPE:
2991cb0ef41Sopenharmony_ci      StoreHandler::cast(*this).StoreHandlerVerify(isolate);
3001cb0ef41Sopenharmony_ci      break;
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci    case BIG_INT_BASE_TYPE:
3031cb0ef41Sopenharmony_ci      BigIntBase::cast(*this).BigIntBaseVerify(isolate);
3041cb0ef41Sopenharmony_ci      break;
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci    case JS_CLASS_CONSTRUCTOR_TYPE:
3071cb0ef41Sopenharmony_ci    case JS_PROMISE_CONSTRUCTOR_TYPE:
3081cb0ef41Sopenharmony_ci    case JS_REG_EXP_CONSTRUCTOR_TYPE:
3091cb0ef41Sopenharmony_ci    case JS_ARRAY_CONSTRUCTOR_TYPE:
3101cb0ef41Sopenharmony_ci#define TYPED_ARRAY_CONSTRUCTORS_SWITCH(Type, type, TYPE, Ctype) \
3111cb0ef41Sopenharmony_ci  case TYPE##_TYPED_ARRAY_CONSTRUCTOR_TYPE:
3121cb0ef41Sopenharmony_ci      TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTORS_SWITCH)
3131cb0ef41Sopenharmony_ci#undef TYPED_ARRAY_CONSTRUCTORS_SWITCH
3141cb0ef41Sopenharmony_ci      JSFunction::cast(*this).JSFunctionVerify(isolate);
3151cb0ef41Sopenharmony_ci      break;
3161cb0ef41Sopenharmony_ci    case JS_LAST_DUMMY_API_OBJECT_TYPE:
3171cb0ef41Sopenharmony_ci      UNREACHABLE();
3181cb0ef41Sopenharmony_ci  }
3191cb0ef41Sopenharmony_ci}
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci// static
3221cb0ef41Sopenharmony_civoid HeapObject::VerifyHeapPointer(Isolate* isolate, Object p) {
3231cb0ef41Sopenharmony_ci  CHECK(p.IsHeapObject());
3241cb0ef41Sopenharmony_ci  CHECK(IsValidHeapObject(isolate->heap(), HeapObject::cast(p)));
3251cb0ef41Sopenharmony_ci  CHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !p.IsCode());
3261cb0ef41Sopenharmony_ci}
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ci// static
3291cb0ef41Sopenharmony_civoid HeapObject::VerifyCodePointer(Isolate* isolate, Object p) {
3301cb0ef41Sopenharmony_ci  CHECK(p.IsHeapObject());
3311cb0ef41Sopenharmony_ci  CHECK(IsValidCodeObject(isolate->heap(), HeapObject::cast(p)));
3321cb0ef41Sopenharmony_ci  PtrComprCageBase cage_base(isolate);
3331cb0ef41Sopenharmony_ci  CHECK(HeapObject::cast(p).IsCode(cage_base));
3341cb0ef41Sopenharmony_ci}
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_civoid Symbol::SymbolVerify(Isolate* isolate) {
3371cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::SymbolVerify(*this, isolate);
3381cb0ef41Sopenharmony_ci  CHECK(HasHashCode());
3391cb0ef41Sopenharmony_ci  CHECK_GT(hash(), 0);
3401cb0ef41Sopenharmony_ci  CHECK(description().IsUndefined(isolate) || description().IsString());
3411cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsPrivateName(), IsPrivate());
3421cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsPrivateBrand(), IsPrivateName());
3431cb0ef41Sopenharmony_ci}
3441cb0ef41Sopenharmony_ci
3451cb0ef41Sopenharmony_civoid BytecodeArray::BytecodeArrayVerify(Isolate* isolate) {
3461cb0ef41Sopenharmony_ci  // TODO(oth): Walk bytecodes and immediate values to validate sanity.
3471cb0ef41Sopenharmony_ci  // - All bytecodes are known and well formed.
3481cb0ef41Sopenharmony_ci  // - Jumps must go to new instructions starts.
3491cb0ef41Sopenharmony_ci  // - No Illegal bytecodes.
3501cb0ef41Sopenharmony_ci  // - No consecutive sequences of prefix Wide / ExtraWide.
3511cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::BytecodeArrayVerify(*this, isolate);
3521cb0ef41Sopenharmony_ci  for (int i = 0; i < constant_pool(isolate).length(); ++i) {
3531cb0ef41Sopenharmony_ci    // No ThinStrings in the constant pool.
3541cb0ef41Sopenharmony_ci    CHECK(!constant_pool(isolate).get(isolate, i).IsThinString(isolate));
3551cb0ef41Sopenharmony_ci  }
3561cb0ef41Sopenharmony_ci}
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_cibool JSObject::ElementsAreSafeToExamine(PtrComprCageBase cage_base) const {
3591cb0ef41Sopenharmony_ci  // If a GC was caused while constructing this object, the elements
3601cb0ef41Sopenharmony_ci  // pointer may point to a one pointer filler map.
3611cb0ef41Sopenharmony_ci  return elements(cage_base) !=
3621cb0ef41Sopenharmony_ci         GetReadOnlyRoots(cage_base).one_pointer_filler_map();
3631cb0ef41Sopenharmony_ci}
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_cinamespace {
3661cb0ef41Sopenharmony_ci
3671cb0ef41Sopenharmony_civoid VerifyJSObjectElements(Isolate* isolate, JSObject object) {
3681cb0ef41Sopenharmony_ci  // Only TypedArrays can have these specialized elements.
3691cb0ef41Sopenharmony_ci  if (object.IsJSTypedArray()) {
3701cb0ef41Sopenharmony_ci    // TODO(bmeurer,v8:4153): Fix CreateTypedArray to either not instantiate
3711cb0ef41Sopenharmony_ci    // the object or propertly initialize it on errors during construction.
3721cb0ef41Sopenharmony_ci    /* CHECK(object->HasTypedArrayOrRabGsabTypedArrayElements()); */
3731cb0ef41Sopenharmony_ci    return;
3741cb0ef41Sopenharmony_ci  }
3751cb0ef41Sopenharmony_ci  CHECK(!object.elements().IsByteArray());
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci  if (object.HasDoubleElements()) {
3781cb0ef41Sopenharmony_ci    if (object.elements().length() > 0) {
3791cb0ef41Sopenharmony_ci      CHECK(object.elements().IsFixedDoubleArray());
3801cb0ef41Sopenharmony_ci    }
3811cb0ef41Sopenharmony_ci    return;
3821cb0ef41Sopenharmony_ci  }
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci  if (object.HasSloppyArgumentsElements()) {
3851cb0ef41Sopenharmony_ci    CHECK(object.elements().IsSloppyArgumentsElements());
3861cb0ef41Sopenharmony_ci    return;
3871cb0ef41Sopenharmony_ci  }
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci  FixedArray elements = FixedArray::cast(object.elements());
3901cb0ef41Sopenharmony_ci  if (object.HasSmiElements()) {
3911cb0ef41Sopenharmony_ci    // We might have a partially initialized backing store, in which case we
3921cb0ef41Sopenharmony_ci    // allow the hole + smi values.
3931cb0ef41Sopenharmony_ci    for (int i = 0; i < elements.length(); i++) {
3941cb0ef41Sopenharmony_ci      Object value = elements.get(i);
3951cb0ef41Sopenharmony_ci      CHECK(value.IsSmi() || value.IsTheHole(isolate));
3961cb0ef41Sopenharmony_ci    }
3971cb0ef41Sopenharmony_ci  } else if (object.HasObjectElements()) {
3981cb0ef41Sopenharmony_ci    for (int i = 0; i < elements.length(); i++) {
3991cb0ef41Sopenharmony_ci      Object element = elements.get(i);
4001cb0ef41Sopenharmony_ci      CHECK(!HasWeakHeapObjectTag(element));
4011cb0ef41Sopenharmony_ci    }
4021cb0ef41Sopenharmony_ci  }
4031cb0ef41Sopenharmony_ci}
4041cb0ef41Sopenharmony_ci}  // namespace
4051cb0ef41Sopenharmony_ci
4061cb0ef41Sopenharmony_civoid JSObject::JSObjectVerify(Isolate* isolate) {
4071cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSObjectVerify(*this, isolate);
4081cb0ef41Sopenharmony_ci  VerifyHeapPointer(isolate, elements());
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci  CHECK_IMPLIES(HasSloppyArgumentsElements(), IsJSArgumentsObject());
4111cb0ef41Sopenharmony_ci  if (HasFastProperties()) {
4121cb0ef41Sopenharmony_ci    int actual_unused_property_fields = map().GetInObjectProperties() +
4131cb0ef41Sopenharmony_ci                                        property_array().length() -
4141cb0ef41Sopenharmony_ci                                        map().NextFreePropertyIndex();
4151cb0ef41Sopenharmony_ci    if (map().UnusedPropertyFields() != actual_unused_property_fields) {
4161cb0ef41Sopenharmony_ci      // There are two reasons why this can happen:
4171cb0ef41Sopenharmony_ci      // - in the middle of StoreTransitionStub when the new extended backing
4181cb0ef41Sopenharmony_ci      //   store is already set into the object and the allocation of the
4191cb0ef41Sopenharmony_ci      //   HeapNumber triggers GC while the map isn't updated yet.
4201cb0ef41Sopenharmony_ci      // - deletion of the last property can leave additional backing store
4211cb0ef41Sopenharmony_ci      //   capacity behind.
4221cb0ef41Sopenharmony_ci      CHECK_GT(actual_unused_property_fields, map().UnusedPropertyFields());
4231cb0ef41Sopenharmony_ci      int delta = actual_unused_property_fields - map().UnusedPropertyFields();
4241cb0ef41Sopenharmony_ci      CHECK_EQ(0, delta % JSObject::kFieldsAdded);
4251cb0ef41Sopenharmony_ci    }
4261cb0ef41Sopenharmony_ci    DescriptorArray descriptors = map().instance_descriptors(isolate);
4271cb0ef41Sopenharmony_ci    bool is_transitionable_fast_elements_kind =
4281cb0ef41Sopenharmony_ci        IsTransitionableFastElementsKind(map().elements_kind());
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci    for (InternalIndex i : map().IterateOwnDescriptors()) {
4311cb0ef41Sopenharmony_ci      PropertyDetails details = descriptors.GetDetails(i);
4321cb0ef41Sopenharmony_ci      if (details.location() == PropertyLocation::kField) {
4331cb0ef41Sopenharmony_ci        DCHECK_EQ(PropertyKind::kData, details.kind());
4341cb0ef41Sopenharmony_ci        Representation r = details.representation();
4351cb0ef41Sopenharmony_ci        FieldIndex index = FieldIndex::ForDescriptor(map(), i);
4361cb0ef41Sopenharmony_ci        if (COMPRESS_POINTERS_BOOL && index.is_inobject()) {
4371cb0ef41Sopenharmony_ci          VerifyObjectField(isolate, index.offset());
4381cb0ef41Sopenharmony_ci        }
4391cb0ef41Sopenharmony_ci        Object value = RawFastPropertyAt(index);
4401cb0ef41Sopenharmony_ci        if (r.IsDouble()) DCHECK(value.IsHeapNumber());
4411cb0ef41Sopenharmony_ci        if (value.IsUninitialized(isolate)) continue;
4421cb0ef41Sopenharmony_ci        if (r.IsSmi()) DCHECK(value.IsSmi());
4431cb0ef41Sopenharmony_ci        if (r.IsHeapObject()) DCHECK(value.IsHeapObject());
4441cb0ef41Sopenharmony_ci        FieldType field_type = descriptors.GetFieldType(i);
4451cb0ef41Sopenharmony_ci        bool type_is_none = field_type.IsNone();
4461cb0ef41Sopenharmony_ci        bool type_is_any = field_type.IsAny();
4471cb0ef41Sopenharmony_ci        if (r.IsNone()) {
4481cb0ef41Sopenharmony_ci          CHECK(type_is_none);
4491cb0ef41Sopenharmony_ci        } else if (!type_is_any && !(type_is_none && r.IsHeapObject())) {
4501cb0ef41Sopenharmony_ci          CHECK(!field_type.NowStable() || field_type.NowContains(value));
4511cb0ef41Sopenharmony_ci        }
4521cb0ef41Sopenharmony_ci        CHECK_IMPLIES(is_transitionable_fast_elements_kind,
4531cb0ef41Sopenharmony_ci                      Map::IsMostGeneralFieldType(r, field_type));
4541cb0ef41Sopenharmony_ci      }
4551cb0ef41Sopenharmony_ci    }
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_ci    if (map().EnumLength() != kInvalidEnumCacheSentinel) {
4581cb0ef41Sopenharmony_ci      EnumCache enum_cache = descriptors.enum_cache();
4591cb0ef41Sopenharmony_ci      FixedArray keys = enum_cache.keys();
4601cb0ef41Sopenharmony_ci      FixedArray indices = enum_cache.indices();
4611cb0ef41Sopenharmony_ci      CHECK_LE(map().EnumLength(), keys.length());
4621cb0ef41Sopenharmony_ci      CHECK_IMPLIES(indices != ReadOnlyRoots(isolate).empty_fixed_array(),
4631cb0ef41Sopenharmony_ci                    keys.length() == indices.length());
4641cb0ef41Sopenharmony_ci    }
4651cb0ef41Sopenharmony_ci  }
4661cb0ef41Sopenharmony_ci
4671cb0ef41Sopenharmony_ci  // If a GC was caused while constructing this object, the elements
4681cb0ef41Sopenharmony_ci  // pointer may point to a one pointer filler map.
4691cb0ef41Sopenharmony_ci  if (ElementsAreSafeToExamine(isolate)) {
4701cb0ef41Sopenharmony_ci    CHECK_EQ((map().has_fast_smi_or_object_elements() ||
4711cb0ef41Sopenharmony_ci              map().has_any_nonextensible_elements() ||
4721cb0ef41Sopenharmony_ci              (elements() == GetReadOnlyRoots().empty_fixed_array()) ||
4731cb0ef41Sopenharmony_ci              HasFastStringWrapperElements()),
4741cb0ef41Sopenharmony_ci             (elements().map() == GetReadOnlyRoots().fixed_array_map() ||
4751cb0ef41Sopenharmony_ci              elements().map() == GetReadOnlyRoots().fixed_cow_array_map()));
4761cb0ef41Sopenharmony_ci    CHECK_EQ(map().has_fast_object_elements(), HasObjectElements());
4771cb0ef41Sopenharmony_ci    VerifyJSObjectElements(isolate, *this);
4781cb0ef41Sopenharmony_ci  }
4791cb0ef41Sopenharmony_ci}
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_civoid Map::MapVerify(Isolate* isolate) {
4821cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::MapVerify(*this, isolate);
4831cb0ef41Sopenharmony_ci  Heap* heap = isolate->heap();
4841cb0ef41Sopenharmony_ci  CHECK(!ObjectInYoungGeneration(*this));
4851cb0ef41Sopenharmony_ci  CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
4861cb0ef41Sopenharmony_ci  CHECK(instance_size() == kVariableSizeSentinel ||
4871cb0ef41Sopenharmony_ci        (kTaggedSize <= instance_size() &&
4881cb0ef41Sopenharmony_ci         static_cast<size_t>(instance_size()) < heap->Capacity()));
4891cb0ef41Sopenharmony_ci  if (IsContextMap()) {
4901cb0ef41Sopenharmony_ci    // The map for the NativeContext is allocated before the NativeContext
4911cb0ef41Sopenharmony_ci    // itself, so it may happen that during a GC the native_context() is still
4921cb0ef41Sopenharmony_ci    // null.
4931cb0ef41Sopenharmony_ci    CHECK(native_context_or_null().IsNull() ||
4941cb0ef41Sopenharmony_ci          native_context().IsNativeContext());
4951cb0ef41Sopenharmony_ci  } else {
4961cb0ef41Sopenharmony_ci    if (GetBackPointer().IsUndefined(isolate)) {
4971cb0ef41Sopenharmony_ci      // Root maps must not have descriptors in the descriptor array that do not
4981cb0ef41Sopenharmony_ci      // belong to the map.
4991cb0ef41Sopenharmony_ci      CHECK_EQ(NumberOfOwnDescriptors(),
5001cb0ef41Sopenharmony_ci               instance_descriptors(isolate).number_of_descriptors());
5011cb0ef41Sopenharmony_ci    } else {
5021cb0ef41Sopenharmony_ci      // If there is a parent map it must be non-stable.
5031cb0ef41Sopenharmony_ci      Map parent = Map::cast(GetBackPointer());
5041cb0ef41Sopenharmony_ci      CHECK(!parent.is_stable());
5051cb0ef41Sopenharmony_ci      DescriptorArray descriptors = instance_descriptors(isolate);
5061cb0ef41Sopenharmony_ci      if (descriptors == parent.instance_descriptors(isolate)) {
5071cb0ef41Sopenharmony_ci        if (NumberOfOwnDescriptors() == parent.NumberOfOwnDescriptors() + 1) {
5081cb0ef41Sopenharmony_ci          // Descriptors sharing through property transitions takes over
5091cb0ef41Sopenharmony_ci          // ownership from the parent map.
5101cb0ef41Sopenharmony_ci          CHECK(!parent.owns_descriptors());
5111cb0ef41Sopenharmony_ci        } else {
5121cb0ef41Sopenharmony_ci          CHECK_EQ(NumberOfOwnDescriptors(), parent.NumberOfOwnDescriptors());
5131cb0ef41Sopenharmony_ci          // Descriptors sharing through special transitions properly takes over
5141cb0ef41Sopenharmony_ci          // ownership from the parent map unless it uses the canonical empty
5151cb0ef41Sopenharmony_ci          // descriptor array.
5161cb0ef41Sopenharmony_ci          if (descriptors != ReadOnlyRoots(isolate).empty_descriptor_array()) {
5171cb0ef41Sopenharmony_ci            CHECK_IMPLIES(owns_descriptors(), !parent.owns_descriptors());
5181cb0ef41Sopenharmony_ci            CHECK_IMPLIES(parent.owns_descriptors(), !owns_descriptors());
5191cb0ef41Sopenharmony_ci          }
5201cb0ef41Sopenharmony_ci        }
5211cb0ef41Sopenharmony_ci      }
5221cb0ef41Sopenharmony_ci    }
5231cb0ef41Sopenharmony_ci  }
5241cb0ef41Sopenharmony_ci  SLOW_DCHECK(instance_descriptors(isolate).IsSortedNoDuplicates());
5251cb0ef41Sopenharmony_ci  SLOW_DCHECK(TransitionsAccessor(isolate, *this).IsSortedNoDuplicates());
5261cb0ef41Sopenharmony_ci  SLOW_DCHECK(
5271cb0ef41Sopenharmony_ci      TransitionsAccessor(isolate, *this).IsConsistentWithBackPointers());
5281cb0ef41Sopenharmony_ci  // Only JSFunction maps have has_prototype_slot() bit set and constructible
5291cb0ef41Sopenharmony_ci  // JSFunction objects must have prototype slot.
5301cb0ef41Sopenharmony_ci  CHECK_IMPLIES(has_prototype_slot(), IsJSFunctionMap());
5311cb0ef41Sopenharmony_ci
5321cb0ef41Sopenharmony_ci  if (IsJSObjectMap()) {
5331cb0ef41Sopenharmony_ci    int header_end_offset = JSObject::GetHeaderSize(*this);
5341cb0ef41Sopenharmony_ci    int inobject_fields_start_offset = GetInObjectPropertyOffset(0);
5351cb0ef41Sopenharmony_ci    // Ensure that embedder fields are located exactly between header and
5361cb0ef41Sopenharmony_ci    // inobject properties.
5371cb0ef41Sopenharmony_ci    CHECK_EQ(header_end_offset, JSObject::GetEmbedderFieldsStartOffset(*this));
5381cb0ef41Sopenharmony_ci    CHECK_EQ(header_end_offset +
5391cb0ef41Sopenharmony_ci                 JSObject::GetEmbedderFieldCount(*this) * kEmbedderDataSlotSize,
5401cb0ef41Sopenharmony_ci             inobject_fields_start_offset);
5411cb0ef41Sopenharmony_ci  }
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ci  if (!may_have_interesting_symbols()) {
5441cb0ef41Sopenharmony_ci    CHECK(!has_named_interceptor());
5451cb0ef41Sopenharmony_ci    CHECK(!is_dictionary_map());
5461cb0ef41Sopenharmony_ci    CHECK(!is_access_check_needed());
5471cb0ef41Sopenharmony_ci    DescriptorArray const descriptors = instance_descriptors(isolate);
5481cb0ef41Sopenharmony_ci    for (InternalIndex i : IterateOwnDescriptors()) {
5491cb0ef41Sopenharmony_ci      CHECK(!descriptors.GetKey(i).IsInterestingSymbol());
5501cb0ef41Sopenharmony_ci    }
5511cb0ef41Sopenharmony_ci  }
5521cb0ef41Sopenharmony_ci  CHECK_IMPLIES(has_named_interceptor(), may_have_interesting_symbols());
5531cb0ef41Sopenharmony_ci  CHECK_IMPLIES(is_dictionary_map(), may_have_interesting_symbols());
5541cb0ef41Sopenharmony_ci  CHECK_IMPLIES(is_access_check_needed(), may_have_interesting_symbols());
5551cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsJSObjectMap() && !CanHaveFastTransitionableElementsKind(),
5561cb0ef41Sopenharmony_ci                IsDictionaryElementsKind(elements_kind()) ||
5571cb0ef41Sopenharmony_ci                    IsTerminalElementsKind(elements_kind()) ||
5581cb0ef41Sopenharmony_ci                    IsAnyHoleyNonextensibleElementsKind(elements_kind()));
5591cb0ef41Sopenharmony_ci  CHECK_IMPLIES(is_deprecated(), !is_stable());
5601cb0ef41Sopenharmony_ci  if (is_prototype_map()) {
5611cb0ef41Sopenharmony_ci    DCHECK(prototype_info() == Smi::zero() ||
5621cb0ef41Sopenharmony_ci           prototype_info().IsPrototypeInfo());
5631cb0ef41Sopenharmony_ci  }
5641cb0ef41Sopenharmony_ci}
5651cb0ef41Sopenharmony_ci
5661cb0ef41Sopenharmony_civoid Map::DictionaryMapVerify(Isolate* isolate) {
5671cb0ef41Sopenharmony_ci  MapVerify(isolate);
5681cb0ef41Sopenharmony_ci  CHECK(is_dictionary_map());
5691cb0ef41Sopenharmony_ci  CHECK_EQ(kInvalidEnumCacheSentinel, EnumLength());
5701cb0ef41Sopenharmony_ci  CHECK_EQ(ReadOnlyRoots(isolate).empty_descriptor_array(),
5711cb0ef41Sopenharmony_ci           instance_descriptors(isolate));
5721cb0ef41Sopenharmony_ci  CHECK_EQ(0, UnusedPropertyFields());
5731cb0ef41Sopenharmony_ci  CHECK_EQ(Map::GetVisitorId(*this), visitor_id());
5741cb0ef41Sopenharmony_ci}
5751cb0ef41Sopenharmony_ci
5761cb0ef41Sopenharmony_civoid EmbedderDataArray::EmbedderDataArrayVerify(Isolate* isolate) {
5771cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::EmbedderDataArrayVerify(*this, isolate);
5781cb0ef41Sopenharmony_ci  EmbedderDataSlot start(*this, 0);
5791cb0ef41Sopenharmony_ci  EmbedderDataSlot end(*this, length());
5801cb0ef41Sopenharmony_ci  for (EmbedderDataSlot slot = start; slot < end; ++slot) {
5811cb0ef41Sopenharmony_ci    Object e = slot.load_tagged();
5821cb0ef41Sopenharmony_ci    Object::VerifyPointer(isolate, e);
5831cb0ef41Sopenharmony_ci  }
5841cb0ef41Sopenharmony_ci}
5851cb0ef41Sopenharmony_ci
5861cb0ef41Sopenharmony_civoid FixedArray::FixedArrayVerify(Isolate* isolate) {
5871cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::FixedArrayVerify(*this, isolate);
5881cb0ef41Sopenharmony_ci  if (*this == ReadOnlyRoots(isolate).empty_fixed_array()) {
5891cb0ef41Sopenharmony_ci    CHECK_EQ(length(), 0);
5901cb0ef41Sopenharmony_ci    CHECK_EQ(map(), ReadOnlyRoots(isolate).fixed_array_map());
5911cb0ef41Sopenharmony_ci  } else if (IsArrayList()) {
5921cb0ef41Sopenharmony_ci    ArrayList::cast(*this).ArrayListVerify(isolate);
5931cb0ef41Sopenharmony_ci  }
5941cb0ef41Sopenharmony_ci}
5951cb0ef41Sopenharmony_ci
5961cb0ef41Sopenharmony_civoid WeakFixedArray::WeakFixedArrayVerify(Isolate* isolate) {
5971cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::WeakFixedArrayVerify(*this, isolate);
5981cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); i++) {
5991cb0ef41Sopenharmony_ci    MaybeObject::VerifyMaybeObjectPointer(isolate, Get(i));
6001cb0ef41Sopenharmony_ci  }
6011cb0ef41Sopenharmony_ci}
6021cb0ef41Sopenharmony_ci
6031cb0ef41Sopenharmony_civoid ArrayList::ArrayListVerify(Isolate* isolate) {
6041cb0ef41Sopenharmony_ci  // Avoid calling the torque-generated ArrayListVerify to prevent an endlessly
6051cb0ef41Sopenharmony_ci  // recursion verification.
6061cb0ef41Sopenharmony_ci  CHECK(IsArrayList());
6071cb0ef41Sopenharmony_ci  CHECK_LE(ArrayList::kLengthIndex, length());
6081cb0ef41Sopenharmony_ci  CHECK_LE(0, Length());
6091cb0ef41Sopenharmony_ci  if (Length() == 0 && length() == ArrayList::kLengthIndex) {
6101cb0ef41Sopenharmony_ci    CHECK_EQ(*this, ReadOnlyRoots(isolate).empty_array_list());
6111cb0ef41Sopenharmony_ci  }
6121cb0ef41Sopenharmony_ci}
6131cb0ef41Sopenharmony_ci
6141cb0ef41Sopenharmony_civoid PropertyArray::PropertyArrayVerify(Isolate* isolate) {
6151cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::PropertyArrayVerify(*this, isolate);
6161cb0ef41Sopenharmony_ci  if (length() == 0) {
6171cb0ef41Sopenharmony_ci    CHECK_EQ(*this, ReadOnlyRoots(isolate).empty_property_array());
6181cb0ef41Sopenharmony_ci    return;
6191cb0ef41Sopenharmony_ci  }
6201cb0ef41Sopenharmony_ci  // There are no empty PropertyArrays.
6211cb0ef41Sopenharmony_ci  CHECK_LT(0, length());
6221cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); i++) {
6231cb0ef41Sopenharmony_ci    Object e = get(i);
6241cb0ef41Sopenharmony_ci    Object::VerifyPointer(isolate, e);
6251cb0ef41Sopenharmony_ci  }
6261cb0ef41Sopenharmony_ci}
6271cb0ef41Sopenharmony_ci
6281cb0ef41Sopenharmony_civoid FixedDoubleArray::FixedDoubleArrayVerify(Isolate* isolate) {
6291cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::FixedDoubleArrayVerify(*this, isolate);
6301cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); i++) {
6311cb0ef41Sopenharmony_ci    if (!is_the_hole(i)) {
6321cb0ef41Sopenharmony_ci      uint64_t value = get_representation(i);
6331cb0ef41Sopenharmony_ci      uint64_t unexpected =
6341cb0ef41Sopenharmony_ci          bit_cast<uint64_t>(std::numeric_limits<double>::quiet_NaN()) &
6351cb0ef41Sopenharmony_ci          uint64_t{0x7FF8000000000000};
6361cb0ef41Sopenharmony_ci      // Create implementation specific sNaN by inverting relevant bit.
6371cb0ef41Sopenharmony_ci      unexpected ^= uint64_t{0x0008000000000000};
6381cb0ef41Sopenharmony_ci      CHECK((value & uint64_t{0x7FF8000000000000}) != unexpected ||
6391cb0ef41Sopenharmony_ci            (value & uint64_t{0x0007FFFFFFFFFFFF}) == uint64_t{0});
6401cb0ef41Sopenharmony_ci    }
6411cb0ef41Sopenharmony_ci  }
6421cb0ef41Sopenharmony_ci}
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_civoid Context::ContextVerify(Isolate* isolate) {
6451cb0ef41Sopenharmony_ci  if (has_extension()) VerifyExtensionSlot(extension());
6461cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ContextVerify(*this, isolate);
6471cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); i++) {
6481cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, OffsetOfElementAt(i));
6491cb0ef41Sopenharmony_ci  }
6501cb0ef41Sopenharmony_ci}
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_civoid NativeContext::NativeContextVerify(Isolate* isolate) {
6531cb0ef41Sopenharmony_ci  ContextVerify(isolate);
6541cb0ef41Sopenharmony_ci  CHECK(retained_maps() == Smi::zero() || retained_maps().IsWeakArrayList());
6551cb0ef41Sopenharmony_ci  CHECK_EQ(length(), NativeContext::NATIVE_CONTEXT_SLOTS);
6561cb0ef41Sopenharmony_ci  CHECK_EQ(kVariableSizeSentinel, map().instance_size());
6571cb0ef41Sopenharmony_ci}
6581cb0ef41Sopenharmony_ci
6591cb0ef41Sopenharmony_civoid FeedbackMetadata::FeedbackMetadataVerify(Isolate* isolate) {
6601cb0ef41Sopenharmony_ci  if (slot_count() == 0 && create_closure_slot_count() == 0) {
6611cb0ef41Sopenharmony_ci    CHECK_EQ(ReadOnlyRoots(isolate).empty_feedback_metadata(), *this);
6621cb0ef41Sopenharmony_ci  } else {
6631cb0ef41Sopenharmony_ci    FeedbackMetadataIterator iter(*this);
6641cb0ef41Sopenharmony_ci    while (iter.HasNext()) {
6651cb0ef41Sopenharmony_ci      iter.Next();
6661cb0ef41Sopenharmony_ci      FeedbackSlotKind kind = iter.kind();
6671cb0ef41Sopenharmony_ci      CHECK_NE(FeedbackSlotKind::kInvalid, kind);
6681cb0ef41Sopenharmony_ci      CHECK_GT(FeedbackSlotKind::kKindsNumber, kind);
6691cb0ef41Sopenharmony_ci    }
6701cb0ef41Sopenharmony_ci  }
6711cb0ef41Sopenharmony_ci}
6721cb0ef41Sopenharmony_ci
6731cb0ef41Sopenharmony_civoid DescriptorArray::DescriptorArrayVerify(Isolate* isolate) {
6741cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::DescriptorArrayVerify(*this, isolate);
6751cb0ef41Sopenharmony_ci  if (number_of_all_descriptors() == 0) {
6761cb0ef41Sopenharmony_ci    CHECK_EQ(ReadOnlyRoots(isolate).empty_descriptor_array(), *this);
6771cb0ef41Sopenharmony_ci    CHECK_EQ(0, number_of_all_descriptors());
6781cb0ef41Sopenharmony_ci    CHECK_EQ(0, number_of_descriptors());
6791cb0ef41Sopenharmony_ci    CHECK_EQ(ReadOnlyRoots(isolate).empty_enum_cache(), enum_cache());
6801cb0ef41Sopenharmony_ci  } else {
6811cb0ef41Sopenharmony_ci    CHECK_LT(0, number_of_all_descriptors());
6821cb0ef41Sopenharmony_ci    CHECK_LE(number_of_descriptors(), number_of_all_descriptors());
6831cb0ef41Sopenharmony_ci
6841cb0ef41Sopenharmony_ci    // Check that properties with private symbols names are non-enumerable, and
6851cb0ef41Sopenharmony_ci    // that fields are in order.
6861cb0ef41Sopenharmony_ci    int expected_field_index = 0;
6871cb0ef41Sopenharmony_ci    for (InternalIndex descriptor :
6881cb0ef41Sopenharmony_ci         InternalIndex::Range(number_of_descriptors())) {
6891cb0ef41Sopenharmony_ci      Object key = *(GetDescriptorSlot(descriptor.as_int()) + kEntryKeyIndex);
6901cb0ef41Sopenharmony_ci      // number_of_descriptors() may be out of sync with the actual descriptors
6911cb0ef41Sopenharmony_ci      // written during descriptor array construction.
6921cb0ef41Sopenharmony_ci      if (key.IsUndefined(isolate)) continue;
6931cb0ef41Sopenharmony_ci      PropertyDetails details = GetDetails(descriptor);
6941cb0ef41Sopenharmony_ci      if (Name::cast(key).IsPrivate()) {
6951cb0ef41Sopenharmony_ci        CHECK_NE(details.attributes() & DONT_ENUM, 0);
6961cb0ef41Sopenharmony_ci      }
6971cb0ef41Sopenharmony_ci      MaybeObject value = GetValue(descriptor);
6981cb0ef41Sopenharmony_ci      HeapObject heap_object;
6991cb0ef41Sopenharmony_ci      if (details.location() == PropertyLocation::kField) {
7001cb0ef41Sopenharmony_ci        CHECK_EQ(details.field_index(), expected_field_index);
7011cb0ef41Sopenharmony_ci        CHECK(
7021cb0ef41Sopenharmony_ci            value == MaybeObject::FromObject(FieldType::None()) ||
7031cb0ef41Sopenharmony_ci            value == MaybeObject::FromObject(FieldType::Any()) ||
7041cb0ef41Sopenharmony_ci            value->IsCleared() ||
7051cb0ef41Sopenharmony_ci            (value->GetHeapObjectIfWeak(&heap_object) && heap_object.IsMap()));
7061cb0ef41Sopenharmony_ci        expected_field_index += details.field_width_in_words();
7071cb0ef41Sopenharmony_ci      } else {
7081cb0ef41Sopenharmony_ci        CHECK(!value->IsWeakOrCleared());
7091cb0ef41Sopenharmony_ci        CHECK(!value->cast<Object>().IsMap());
7101cb0ef41Sopenharmony_ci      }
7111cb0ef41Sopenharmony_ci    }
7121cb0ef41Sopenharmony_ci  }
7131cb0ef41Sopenharmony_ci}
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_civoid TransitionArray::TransitionArrayVerify(Isolate* isolate) {
7161cb0ef41Sopenharmony_ci  WeakFixedArrayVerify(isolate);
7171cb0ef41Sopenharmony_ci  CHECK_LE(LengthFor(number_of_transitions()), length());
7181cb0ef41Sopenharmony_ci}
7191cb0ef41Sopenharmony_ci
7201cb0ef41Sopenharmony_cinamespace {
7211cb0ef41Sopenharmony_civoid SloppyArgumentsElementsVerify(Isolate* isolate,
7221cb0ef41Sopenharmony_ci                                   SloppyArgumentsElements elements,
7231cb0ef41Sopenharmony_ci                                   JSObject holder) {
7241cb0ef41Sopenharmony_ci  elements.SloppyArgumentsElementsVerify(isolate);
7251cb0ef41Sopenharmony_ci  ElementsKind kind = holder.GetElementsKind();
7261cb0ef41Sopenharmony_ci  bool is_fast = kind == FAST_SLOPPY_ARGUMENTS_ELEMENTS;
7271cb0ef41Sopenharmony_ci  Context context_object = elements.context();
7281cb0ef41Sopenharmony_ci  FixedArray arg_elements = elements.arguments();
7291cb0ef41Sopenharmony_ci  if (arg_elements.length() == 0) {
7301cb0ef41Sopenharmony_ci    CHECK(arg_elements == ReadOnlyRoots(isolate).empty_fixed_array());
7311cb0ef41Sopenharmony_ci    return;
7321cb0ef41Sopenharmony_ci  }
7331cb0ef41Sopenharmony_ci  ElementsAccessor* accessor;
7341cb0ef41Sopenharmony_ci  if (is_fast) {
7351cb0ef41Sopenharmony_ci    accessor = ElementsAccessor::ForKind(HOLEY_ELEMENTS);
7361cb0ef41Sopenharmony_ci  } else {
7371cb0ef41Sopenharmony_ci    accessor = ElementsAccessor::ForKind(DICTIONARY_ELEMENTS);
7381cb0ef41Sopenharmony_ci  }
7391cb0ef41Sopenharmony_ci  int nofMappedParameters = 0;
7401cb0ef41Sopenharmony_ci  int maxMappedIndex = 0;
7411cb0ef41Sopenharmony_ci  for (int i = 0; i < nofMappedParameters; i++) {
7421cb0ef41Sopenharmony_ci    // Verify that each context-mapped argument is either the hole or a valid
7431cb0ef41Sopenharmony_ci    // Smi within context length range.
7441cb0ef41Sopenharmony_ci    Object mapped = elements.mapped_entries(i, kRelaxedLoad);
7451cb0ef41Sopenharmony_ci    if (mapped.IsTheHole(isolate)) {
7461cb0ef41Sopenharmony_ci      // Slow sloppy arguments can be holey.
7471cb0ef41Sopenharmony_ci      if (!is_fast) continue;
7481cb0ef41Sopenharmony_ci      // Fast sloppy arguments elements are never holey. Either the element is
7491cb0ef41Sopenharmony_ci      // context-mapped or present in the arguments elements.
7501cb0ef41Sopenharmony_ci      CHECK(accessor->HasElement(holder, i, arg_elements));
7511cb0ef41Sopenharmony_ci      continue;
7521cb0ef41Sopenharmony_ci    }
7531cb0ef41Sopenharmony_ci    int mappedIndex = Smi::ToInt(mapped);
7541cb0ef41Sopenharmony_ci    nofMappedParameters++;
7551cb0ef41Sopenharmony_ci    CHECK_LE(maxMappedIndex, mappedIndex);
7561cb0ef41Sopenharmony_ci    maxMappedIndex = mappedIndex;
7571cb0ef41Sopenharmony_ci    Object value = context_object.get(mappedIndex);
7581cb0ef41Sopenharmony_ci    CHECK(value.IsObject());
7591cb0ef41Sopenharmony_ci    // None of the context-mapped entries should exist in the arguments
7601cb0ef41Sopenharmony_ci    // elements.
7611cb0ef41Sopenharmony_ci    CHECK(!accessor->HasElement(holder, i, arg_elements));
7621cb0ef41Sopenharmony_ci  }
7631cb0ef41Sopenharmony_ci  CHECK_LE(nofMappedParameters, context_object.length());
7641cb0ef41Sopenharmony_ci  CHECK_LE(nofMappedParameters, arg_elements.length());
7651cb0ef41Sopenharmony_ci  CHECK_LE(maxMappedIndex, context_object.length());
7661cb0ef41Sopenharmony_ci  CHECK_LE(maxMappedIndex, arg_elements.length());
7671cb0ef41Sopenharmony_ci}
7681cb0ef41Sopenharmony_ci}  // namespace
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_civoid JSArgumentsObject::JSArgumentsObjectVerify(Isolate* isolate) {
7711cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSArgumentsObjectVerify(*this, isolate);
7721cb0ef41Sopenharmony_ci  if (IsSloppyArgumentsElementsKind(GetElementsKind())) {
7731cb0ef41Sopenharmony_ci    SloppyArgumentsElementsVerify(
7741cb0ef41Sopenharmony_ci        isolate, SloppyArgumentsElements::cast(elements()), *this);
7751cb0ef41Sopenharmony_ci  }
7761cb0ef41Sopenharmony_ci  if (isolate->IsInAnyContext(map(), Context::SLOPPY_ARGUMENTS_MAP_INDEX) ||
7771cb0ef41Sopenharmony_ci      isolate->IsInAnyContext(map(),
7781cb0ef41Sopenharmony_ci                              Context::SLOW_ALIASED_ARGUMENTS_MAP_INDEX) ||
7791cb0ef41Sopenharmony_ci      isolate->IsInAnyContext(map(),
7801cb0ef41Sopenharmony_ci                              Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX)) {
7811cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, JSSloppyArgumentsObject::kLengthOffset);
7821cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, JSSloppyArgumentsObject::kCalleeOffset);
7831cb0ef41Sopenharmony_ci  } else if (isolate->IsInAnyContext(map(),
7841cb0ef41Sopenharmony_ci                                     Context::STRICT_ARGUMENTS_MAP_INDEX)) {
7851cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, JSStrictArgumentsObject::kLengthOffset);
7861cb0ef41Sopenharmony_ci  }
7871cb0ef41Sopenharmony_ci}
7881cb0ef41Sopenharmony_ci
7891cb0ef41Sopenharmony_civoid JSAsyncFunctionObject::JSAsyncFunctionObjectVerify(Isolate* isolate) {
7901cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSAsyncFunctionObjectVerify(*this, isolate);
7911cb0ef41Sopenharmony_ci}
7921cb0ef41Sopenharmony_ci
7931cb0ef41Sopenharmony_civoid JSAsyncGeneratorObject::JSAsyncGeneratorObjectVerify(Isolate* isolate) {
7941cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSAsyncGeneratorObjectVerify(*this, isolate);
7951cb0ef41Sopenharmony_ci}
7961cb0ef41Sopenharmony_ci
7971cb0ef41Sopenharmony_civoid JSDate::JSDateVerify(Isolate* isolate) {
7981cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSDateVerify(*this, isolate);
7991cb0ef41Sopenharmony_ci
8001cb0ef41Sopenharmony_ci  if (month().IsSmi()) {
8011cb0ef41Sopenharmony_ci    int month = Smi::ToInt(this->month());
8021cb0ef41Sopenharmony_ci    CHECK(0 <= month && month <= 11);
8031cb0ef41Sopenharmony_ci  }
8041cb0ef41Sopenharmony_ci  if (day().IsSmi()) {
8051cb0ef41Sopenharmony_ci    int day = Smi::ToInt(this->day());
8061cb0ef41Sopenharmony_ci    CHECK(1 <= day && day <= 31);
8071cb0ef41Sopenharmony_ci  }
8081cb0ef41Sopenharmony_ci  if (hour().IsSmi()) {
8091cb0ef41Sopenharmony_ci    int hour = Smi::ToInt(this->hour());
8101cb0ef41Sopenharmony_ci    CHECK(0 <= hour && hour <= 23);
8111cb0ef41Sopenharmony_ci  }
8121cb0ef41Sopenharmony_ci  if (min().IsSmi()) {
8131cb0ef41Sopenharmony_ci    int min = Smi::ToInt(this->min());
8141cb0ef41Sopenharmony_ci    CHECK(0 <= min && min <= 59);
8151cb0ef41Sopenharmony_ci  }
8161cb0ef41Sopenharmony_ci  if (sec().IsSmi()) {
8171cb0ef41Sopenharmony_ci    int sec = Smi::ToInt(this->sec());
8181cb0ef41Sopenharmony_ci    CHECK(0 <= sec && sec <= 59);
8191cb0ef41Sopenharmony_ci  }
8201cb0ef41Sopenharmony_ci  if (weekday().IsSmi()) {
8211cb0ef41Sopenharmony_ci    int weekday = Smi::ToInt(this->weekday());
8221cb0ef41Sopenharmony_ci    CHECK(0 <= weekday && weekday <= 6);
8231cb0ef41Sopenharmony_ci  }
8241cb0ef41Sopenharmony_ci  if (cache_stamp().IsSmi()) {
8251cb0ef41Sopenharmony_ci    CHECK(Smi::ToInt(cache_stamp()) <=
8261cb0ef41Sopenharmony_ci          Smi::ToInt(isolate->date_cache()->stamp()));
8271cb0ef41Sopenharmony_ci  }
8281cb0ef41Sopenharmony_ci}
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_civoid String::StringVerify(Isolate* isolate) {
8311cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::StringVerify(*this, isolate);
8321cb0ef41Sopenharmony_ci  CHECK(length() >= 0 && length() <= Smi::kMaxValue);
8331cb0ef41Sopenharmony_ci  CHECK_IMPLIES(length() == 0, *this == ReadOnlyRoots(isolate).empty_string());
8341cb0ef41Sopenharmony_ci  if (IsInternalizedString()) {
8351cb0ef41Sopenharmony_ci    CHECK(!ObjectInYoungGeneration(*this));
8361cb0ef41Sopenharmony_ci  }
8371cb0ef41Sopenharmony_ci}
8381cb0ef41Sopenharmony_ci
8391cb0ef41Sopenharmony_civoid ConsString::ConsStringVerify(Isolate* isolate) {
8401cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ConsStringVerify(*this, isolate);
8411cb0ef41Sopenharmony_ci  CHECK_GE(length(), ConsString::kMinLength);
8421cb0ef41Sopenharmony_ci  CHECK(length() == first().length() + second().length());
8431cb0ef41Sopenharmony_ci  if (IsFlat(isolate)) {
8441cb0ef41Sopenharmony_ci    // A flat cons can only be created by String::SlowFlatten.
8451cb0ef41Sopenharmony_ci    // Afterwards, the first part may be externalized or internalized.
8461cb0ef41Sopenharmony_ci    CHECK(first().IsSeqString() || first().IsExternalString() ||
8471cb0ef41Sopenharmony_ci          first().IsThinString());
8481cb0ef41Sopenharmony_ci  }
8491cb0ef41Sopenharmony_ci}
8501cb0ef41Sopenharmony_ci
8511cb0ef41Sopenharmony_civoid ThinString::ThinStringVerify(Isolate* isolate) {
8521cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ThinStringVerify(*this, isolate);
8531cb0ef41Sopenharmony_ci  CHECK(actual().IsInternalizedString());
8541cb0ef41Sopenharmony_ci  CHECK(actual().IsSeqString() || actual().IsExternalString());
8551cb0ef41Sopenharmony_ci}
8561cb0ef41Sopenharmony_ci
8571cb0ef41Sopenharmony_civoid SlicedString::SlicedStringVerify(Isolate* isolate) {
8581cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::SlicedStringVerify(*this, isolate);
8591cb0ef41Sopenharmony_ci  CHECK(!parent().IsConsString());
8601cb0ef41Sopenharmony_ci  CHECK(!parent().IsSlicedString());
8611cb0ef41Sopenharmony_ci  CHECK_GE(length(), SlicedString::kMinLength);
8621cb0ef41Sopenharmony_ci}
8631cb0ef41Sopenharmony_ci
8641cb0ef41Sopenharmony_ciUSE_TORQUE_VERIFIER(ExternalString)
8651cb0ef41Sopenharmony_ci
8661cb0ef41Sopenharmony_civoid JSBoundFunction::JSBoundFunctionVerify(Isolate* isolate) {
8671cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSBoundFunctionVerify(*this, isolate);
8681cb0ef41Sopenharmony_ci  CHECK(IsCallable());
8691cb0ef41Sopenharmony_ci  CHECK_EQ(IsConstructor(), bound_target_function().IsConstructor());
8701cb0ef41Sopenharmony_ci}
8711cb0ef41Sopenharmony_ci
8721cb0ef41Sopenharmony_civoid JSFunction::JSFunctionVerify(Isolate* isolate) {
8731cb0ef41Sopenharmony_ci  // Don't call TorqueGeneratedClassVerifiers::JSFunctionVerify here because the
8741cb0ef41Sopenharmony_ci  // Torque class definition contains the field `prototype_or_initial_map` which
8751cb0ef41Sopenharmony_ci  // may not be allocated.
8761cb0ef41Sopenharmony_ci
8771cb0ef41Sopenharmony_ci  // This assertion exists to encourage updating this verification function if
8781cb0ef41Sopenharmony_ci  // new fields are added in the Torque class layout definition.
8791cb0ef41Sopenharmony_ci  STATIC_ASSERT(JSFunction::TorqueGeneratedClass::kHeaderSize ==
8801cb0ef41Sopenharmony_ci                8 * kTaggedSize);
8811cb0ef41Sopenharmony_ci
8821cb0ef41Sopenharmony_ci  JSFunctionOrBoundFunctionOrWrappedFunctionVerify(isolate);
8831cb0ef41Sopenharmony_ci  CHECK(IsJSFunction());
8841cb0ef41Sopenharmony_ci  VerifyPointer(isolate, shared(isolate));
8851cb0ef41Sopenharmony_ci  CHECK(shared(isolate).IsSharedFunctionInfo());
8861cb0ef41Sopenharmony_ci  VerifyPointer(isolate, context(isolate, kRelaxedLoad));
8871cb0ef41Sopenharmony_ci  CHECK(context(isolate, kRelaxedLoad).IsContext());
8881cb0ef41Sopenharmony_ci  VerifyPointer(isolate, raw_feedback_cell(isolate));
8891cb0ef41Sopenharmony_ci  CHECK(raw_feedback_cell(isolate).IsFeedbackCell());
8901cb0ef41Sopenharmony_ci  VerifyPointer(isolate, code(isolate));
8911cb0ef41Sopenharmony_ci  CHECK(code(isolate).IsCodeT());
8921cb0ef41Sopenharmony_ci  CHECK(map(isolate).is_callable());
8931cb0ef41Sopenharmony_ci  Handle<JSFunction> function(*this, isolate);
8941cb0ef41Sopenharmony_ci  LookupIterator it(isolate, function, isolate->factory()->prototype_string(),
8951cb0ef41Sopenharmony_ci                    LookupIterator::OWN_SKIP_INTERCEPTOR);
8961cb0ef41Sopenharmony_ci  if (has_prototype_slot()) {
8971cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, kPrototypeOrInitialMapOffset);
8981cb0ef41Sopenharmony_ci  }
8991cb0ef41Sopenharmony_ci
9001cb0ef41Sopenharmony_ci  if (has_prototype_property()) {
9011cb0ef41Sopenharmony_ci    CHECK(it.IsFound());
9021cb0ef41Sopenharmony_ci    CHECK_EQ(LookupIterator::ACCESSOR, it.state());
9031cb0ef41Sopenharmony_ci    CHECK(it.GetAccessors()->IsAccessorInfo());
9041cb0ef41Sopenharmony_ci  } else {
9051cb0ef41Sopenharmony_ci    CHECK(!it.IsFound() || it.state() != LookupIterator::ACCESSOR ||
9061cb0ef41Sopenharmony_ci          !it.GetAccessors()->IsAccessorInfo());
9071cb0ef41Sopenharmony_ci  }
9081cb0ef41Sopenharmony_ci}
9091cb0ef41Sopenharmony_ci
9101cb0ef41Sopenharmony_civoid SharedFunctionInfo::SharedFunctionInfoVerify(Isolate* isolate) {
9111cb0ef41Sopenharmony_ci  // TODO(leszeks): Add a TorqueGeneratedClassVerifier for LocalIsolate.
9121cb0ef41Sopenharmony_ci  this->SharedFunctionInfoVerify(ReadOnlyRoots(isolate));
9131cb0ef41Sopenharmony_ci}
9141cb0ef41Sopenharmony_ci
9151cb0ef41Sopenharmony_civoid SharedFunctionInfo::SharedFunctionInfoVerify(LocalIsolate* isolate) {
9161cb0ef41Sopenharmony_ci  this->SharedFunctionInfoVerify(ReadOnlyRoots(isolate));
9171cb0ef41Sopenharmony_ci}
9181cb0ef41Sopenharmony_ci
9191cb0ef41Sopenharmony_civoid SharedFunctionInfo::SharedFunctionInfoVerify(ReadOnlyRoots roots) {
9201cb0ef41Sopenharmony_ci  Object value = name_or_scope_info(kAcquireLoad);
9211cb0ef41Sopenharmony_ci  if (value.IsScopeInfo()) {
9221cb0ef41Sopenharmony_ci    CHECK(!ScopeInfo::cast(value).IsEmpty());
9231cb0ef41Sopenharmony_ci    CHECK_NE(value, roots.empty_scope_info());
9241cb0ef41Sopenharmony_ci  }
9251cb0ef41Sopenharmony_ci
9261cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
9271cb0ef41Sopenharmony_ci  bool is_wasm = HasWasmExportedFunctionData() || HasAsmWasmData() ||
9281cb0ef41Sopenharmony_ci                 HasWasmJSFunctionData() || HasWasmCapiFunctionData() ||
9291cb0ef41Sopenharmony_ci                 HasWasmOnFulfilledData();
9301cb0ef41Sopenharmony_ci#else
9311cb0ef41Sopenharmony_ci  bool is_wasm = false;
9321cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
9331cb0ef41Sopenharmony_ci  CHECK(is_wasm || IsApiFunction() || HasBytecodeArray() || HasBuiltinId() ||
9341cb0ef41Sopenharmony_ci        HasUncompiledDataWithPreparseData() ||
9351cb0ef41Sopenharmony_ci        HasUncompiledDataWithoutPreparseData());
9361cb0ef41Sopenharmony_ci
9371cb0ef41Sopenharmony_ci  {
9381cb0ef41Sopenharmony_ci    auto script = script_or_debug_info(kAcquireLoad);
9391cb0ef41Sopenharmony_ci    CHECK(script.IsUndefined(roots) || script.IsScript() ||
9401cb0ef41Sopenharmony_ci          script.IsDebugInfo());
9411cb0ef41Sopenharmony_ci  }
9421cb0ef41Sopenharmony_ci
9431cb0ef41Sopenharmony_ci  if (!is_compiled()) {
9441cb0ef41Sopenharmony_ci    CHECK(!HasFeedbackMetadata());
9451cb0ef41Sopenharmony_ci    CHECK(outer_scope_info().IsScopeInfo() ||
9461cb0ef41Sopenharmony_ci          outer_scope_info().IsTheHole(roots));
9471cb0ef41Sopenharmony_ci  } else if (HasBytecodeArray() && HasFeedbackMetadata()) {
9481cb0ef41Sopenharmony_ci    CHECK(feedback_metadata().IsFeedbackMetadata());
9491cb0ef41Sopenharmony_ci  }
9501cb0ef41Sopenharmony_ci
9511cb0ef41Sopenharmony_ci  int expected_map_index =
9521cb0ef41Sopenharmony_ci      Context::FunctionMapIndex(language_mode(), kind(), HasSharedName());
9531cb0ef41Sopenharmony_ci  CHECK_EQ(expected_map_index, function_map_index());
9541cb0ef41Sopenharmony_ci
9551cb0ef41Sopenharmony_ci  if (!scope_info().IsEmpty()) {
9561cb0ef41Sopenharmony_ci    ScopeInfo info = scope_info();
9571cb0ef41Sopenharmony_ci    CHECK(kind() == info.function_kind());
9581cb0ef41Sopenharmony_ci    CHECK_EQ(internal::IsModule(kind()), info.scope_type() == MODULE_SCOPE);
9591cb0ef41Sopenharmony_ci  }
9601cb0ef41Sopenharmony_ci
9611cb0ef41Sopenharmony_ci  if (IsApiFunction()) {
9621cb0ef41Sopenharmony_ci    CHECK(construct_as_builtin());
9631cb0ef41Sopenharmony_ci  } else if (!HasBuiltinId()) {
9641cb0ef41Sopenharmony_ci    CHECK(!construct_as_builtin());
9651cb0ef41Sopenharmony_ci  } else {
9661cb0ef41Sopenharmony_ci    if (builtin_id() != Builtin::kCompileLazy &&
9671cb0ef41Sopenharmony_ci        builtin_id() != Builtin::kEmptyFunction) {
9681cb0ef41Sopenharmony_ci      CHECK(construct_as_builtin());
9691cb0ef41Sopenharmony_ci    } else {
9701cb0ef41Sopenharmony_ci      CHECK(!construct_as_builtin());
9711cb0ef41Sopenharmony_ci    }
9721cb0ef41Sopenharmony_ci  }
9731cb0ef41Sopenharmony_ci}
9741cb0ef41Sopenharmony_ci
9751cb0ef41Sopenharmony_civoid JSGlobalProxy::JSGlobalProxyVerify(Isolate* isolate) {
9761cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSGlobalProxyVerify(*this, isolate);
9771cb0ef41Sopenharmony_ci  CHECK(map().is_access_check_needed());
9781cb0ef41Sopenharmony_ci  // Make sure that this object has no properties, elements.
9791cb0ef41Sopenharmony_ci  CHECK_EQ(0, FixedArray::cast(elements()).length());
9801cb0ef41Sopenharmony_ci}
9811cb0ef41Sopenharmony_ci
9821cb0ef41Sopenharmony_civoid JSGlobalObject::JSGlobalObjectVerify(Isolate* isolate) {
9831cb0ef41Sopenharmony_ci  CHECK(IsJSGlobalObject());
9841cb0ef41Sopenharmony_ci  // Do not check the dummy global object for the builtins.
9851cb0ef41Sopenharmony_ci  if (global_dictionary(kAcquireLoad).NumberOfElements() == 0 &&
9861cb0ef41Sopenharmony_ci      elements().length() == 0) {
9871cb0ef41Sopenharmony_ci    return;
9881cb0ef41Sopenharmony_ci  }
9891cb0ef41Sopenharmony_ci  JSObjectVerify(isolate);
9901cb0ef41Sopenharmony_ci}
9911cb0ef41Sopenharmony_ci
9921cb0ef41Sopenharmony_civoid Oddball::OddballVerify(Isolate* isolate) {
9931cb0ef41Sopenharmony_ci  PrimitiveHeapObjectVerify(isolate);
9941cb0ef41Sopenharmony_ci  CHECK(IsOddball(isolate));
9951cb0ef41Sopenharmony_ci
9961cb0ef41Sopenharmony_ci  Heap* heap = isolate->heap();
9971cb0ef41Sopenharmony_ci  Object string = to_string();
9981cb0ef41Sopenharmony_ci  VerifyPointer(isolate, string);
9991cb0ef41Sopenharmony_ci  CHECK(string.IsString());
10001cb0ef41Sopenharmony_ci  Object type = type_of();
10011cb0ef41Sopenharmony_ci  VerifyPointer(isolate, type);
10021cb0ef41Sopenharmony_ci  CHECK(type.IsString());
10031cb0ef41Sopenharmony_ci  Object kind_value = TaggedField<Object>::load(*this, kKindOffset);
10041cb0ef41Sopenharmony_ci  VerifyPointer(isolate, kind_value);
10051cb0ef41Sopenharmony_ci  CHECK(kind_value.IsSmi());
10061cb0ef41Sopenharmony_ci
10071cb0ef41Sopenharmony_ci  Object number = to_number();
10081cb0ef41Sopenharmony_ci  VerifyPointer(isolate, number);
10091cb0ef41Sopenharmony_ci  CHECK(number.IsSmi() || number.IsHeapNumber());
10101cb0ef41Sopenharmony_ci  if (number.IsHeapObject()) {
10111cb0ef41Sopenharmony_ci    CHECK(number == ReadOnlyRoots(heap).nan_value() ||
10121cb0ef41Sopenharmony_ci          number == ReadOnlyRoots(heap).hole_nan_value());
10131cb0ef41Sopenharmony_ci  } else {
10141cb0ef41Sopenharmony_ci    CHECK(number.IsSmi());
10151cb0ef41Sopenharmony_ci    int value = Smi::ToInt(number);
10161cb0ef41Sopenharmony_ci    // Hidden oddballs have negative smis.
10171cb0ef41Sopenharmony_ci    const int kLeastHiddenOddballNumber = -7;
10181cb0ef41Sopenharmony_ci    CHECK_LE(value, 1);
10191cb0ef41Sopenharmony_ci    CHECK_GE(value, kLeastHiddenOddballNumber);
10201cb0ef41Sopenharmony_ci  }
10211cb0ef41Sopenharmony_ci
10221cb0ef41Sopenharmony_ci  ReadOnlyRoots roots(heap);
10231cb0ef41Sopenharmony_ci  if (map() == roots.undefined_map()) {
10241cb0ef41Sopenharmony_ci    CHECK(*this == roots.undefined_value());
10251cb0ef41Sopenharmony_ci  } else if (map() == roots.the_hole_map()) {
10261cb0ef41Sopenharmony_ci    CHECK(*this == roots.the_hole_value());
10271cb0ef41Sopenharmony_ci  } else if (map() == roots.null_map()) {
10281cb0ef41Sopenharmony_ci    CHECK(*this == roots.null_value());
10291cb0ef41Sopenharmony_ci  } else if (map() == roots.boolean_map()) {
10301cb0ef41Sopenharmony_ci    CHECK(*this == roots.true_value() || *this == roots.false_value());
10311cb0ef41Sopenharmony_ci  } else if (map() == roots.uninitialized_map()) {
10321cb0ef41Sopenharmony_ci    CHECK(*this == roots.uninitialized_value());
10331cb0ef41Sopenharmony_ci  } else if (map() == roots.arguments_marker_map()) {
10341cb0ef41Sopenharmony_ci    CHECK(*this == roots.arguments_marker());
10351cb0ef41Sopenharmony_ci  } else if (map() == roots.termination_exception_map()) {
10361cb0ef41Sopenharmony_ci    CHECK(*this == roots.termination_exception());
10371cb0ef41Sopenharmony_ci  } else if (map() == roots.exception_map()) {
10381cb0ef41Sopenharmony_ci    CHECK(*this == roots.exception());
10391cb0ef41Sopenharmony_ci  } else if (map() == roots.optimized_out_map()) {
10401cb0ef41Sopenharmony_ci    CHECK(*this == roots.optimized_out());
10411cb0ef41Sopenharmony_ci  } else if (map() == roots.stale_register_map()) {
10421cb0ef41Sopenharmony_ci    CHECK(*this == roots.stale_register());
10431cb0ef41Sopenharmony_ci  } else if (map() == roots.self_reference_marker_map()) {
10441cb0ef41Sopenharmony_ci    // Multiple instances of this oddball may exist at once.
10451cb0ef41Sopenharmony_ci    CHECK_EQ(kind(), Oddball::kSelfReferenceMarker);
10461cb0ef41Sopenharmony_ci  } else if (map() == roots.basic_block_counters_marker_map()) {
10471cb0ef41Sopenharmony_ci    CHECK(*this == roots.basic_block_counters_marker());
10481cb0ef41Sopenharmony_ci  } else {
10491cb0ef41Sopenharmony_ci    UNREACHABLE();
10501cb0ef41Sopenharmony_ci  }
10511cb0ef41Sopenharmony_ci}
10521cb0ef41Sopenharmony_ci
10531cb0ef41Sopenharmony_civoid PropertyCell::PropertyCellVerify(Isolate* isolate) {
10541cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::PropertyCellVerify(*this, isolate);
10551cb0ef41Sopenharmony_ci  CHECK(name().IsUniqueName());
10561cb0ef41Sopenharmony_ci  CheckDataIsCompatible(property_details(), value());
10571cb0ef41Sopenharmony_ci}
10581cb0ef41Sopenharmony_ci
10591cb0ef41Sopenharmony_civoid CodeDataContainer::CodeDataContainerVerify(Isolate* isolate) {
10601cb0ef41Sopenharmony_ci  CHECK(IsCodeDataContainer());
10611cb0ef41Sopenharmony_ci  VerifyObjectField(isolate, kNextCodeLinkOffset);
10621cb0ef41Sopenharmony_ci  CHECK(next_code_link().IsCodeT() || next_code_link().IsUndefined(isolate));
10631cb0ef41Sopenharmony_ci  if (V8_EXTERNAL_CODE_SPACE_BOOL) {
10641cb0ef41Sopenharmony_ci    if (raw_code() != Smi::zero()) {
10651cb0ef41Sopenharmony_ci#ifdef V8_EXTERNAL_CODE_SPACE
10661cb0ef41Sopenharmony_ci      // kind and builtin_id() getters are not available on CodeDataContainer
10671cb0ef41Sopenharmony_ci      // when external code space is not enabled.
10681cb0ef41Sopenharmony_ci      CHECK_EQ(code().kind(), kind());
10691cb0ef41Sopenharmony_ci      CHECK_EQ(code().builtin_id(), builtin_id());
10701cb0ef41Sopenharmony_ci#endif  // V8_EXTERNAL_CODE_SPACE
10711cb0ef41Sopenharmony_ci      CHECK_EQ(code().code_data_container(kAcquireLoad), *this);
10721cb0ef41Sopenharmony_ci
10731cb0ef41Sopenharmony_ci      // Ensure the cached code entry point corresponds to the Code object
10741cb0ef41Sopenharmony_ci      // associated with this CodeDataContainer.
10751cb0ef41Sopenharmony_ci#ifdef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
10761cb0ef41Sopenharmony_ci      if (V8_SHORT_BUILTIN_CALLS_BOOL) {
10771cb0ef41Sopenharmony_ci        if (code().InstructionStart() == code_entry_point()) {
10781cb0ef41Sopenharmony_ci          // Most common case, all good.
10791cb0ef41Sopenharmony_ci        } else {
10801cb0ef41Sopenharmony_ci          // When shared pointer compression cage is enabled and it has the
10811cb0ef41Sopenharmony_ci          // embedded code blob copy then the Code::InstructionStart() might
10821cb0ef41Sopenharmony_ci          // return address of the remapped builtin regardless of whether the
10831cb0ef41Sopenharmony_ci          // builtins copy exsisted when the code_entry_point value was cached
10841cb0ef41Sopenharmony_ci          // in the CodeDataContainer (see Code::OffHeapInstructionStart()).
10851cb0ef41Sopenharmony_ci          // So, do a reverse Code object lookup via code_entry_point value to
10861cb0ef41Sopenharmony_ci          // ensure it corresponds to the same Code object associated with this
10871cb0ef41Sopenharmony_ci          // CodeDataContainer.
10881cb0ef41Sopenharmony_ci          Code the_code = isolate->heap()->GcSafeFindCodeForInnerPointer(
10891cb0ef41Sopenharmony_ci              code_entry_point());
10901cb0ef41Sopenharmony_ci          CHECK_EQ(the_code, code());
10911cb0ef41Sopenharmony_ci        }
10921cb0ef41Sopenharmony_ci      } else {
10931cb0ef41Sopenharmony_ci        CHECK_EQ(code().InstructionStart(), code_entry_point());
10941cb0ef41Sopenharmony_ci      }
10951cb0ef41Sopenharmony_ci#else
10961cb0ef41Sopenharmony_ci      CHECK_EQ(code().InstructionStart(), code_entry_point());
10971cb0ef41Sopenharmony_ci#endif  // V8_COMPRESS_POINTERS_IN_SHARED_CAGE
10981cb0ef41Sopenharmony_ci    }
10991cb0ef41Sopenharmony_ci  }
11001cb0ef41Sopenharmony_ci}
11011cb0ef41Sopenharmony_ci
11021cb0ef41Sopenharmony_civoid Code::CodeVerify(Isolate* isolate) {
11031cb0ef41Sopenharmony_ci  CHECK(IsAligned(InstructionSize(),
11041cb0ef41Sopenharmony_ci                  static_cast<unsigned>(Code::kMetadataAlignment)));
11051cb0ef41Sopenharmony_ci  CHECK_EQ(safepoint_table_offset(), 0);
11061cb0ef41Sopenharmony_ci  CHECK_LE(safepoint_table_offset(), handler_table_offset());
11071cb0ef41Sopenharmony_ci  CHECK_LE(handler_table_offset(), constant_pool_offset());
11081cb0ef41Sopenharmony_ci  CHECK_LE(constant_pool_offset(), code_comments_offset());
11091cb0ef41Sopenharmony_ci  CHECK_LE(code_comments_offset(), unwinding_info_offset());
11101cb0ef41Sopenharmony_ci  CHECK_LE(unwinding_info_offset(), MetadataSize());
11111cb0ef41Sopenharmony_ci#if !defined(_MSC_VER) || defined(__clang__)
11121cb0ef41Sopenharmony_ci  // See also: PlatformEmbeddedFileWriterWin::AlignToCodeAlignment.
11131cb0ef41Sopenharmony_ci  CHECK_IMPLIES(!ReadOnlyHeap::Contains(*this),
11141cb0ef41Sopenharmony_ci                IsAligned(InstructionStart(), kCodeAlignment));
11151cb0ef41Sopenharmony_ci#endif  // !defined(_MSC_VER) || defined(__clang__)
11161cb0ef41Sopenharmony_ci  CHECK_IMPLIES(!ReadOnlyHeap::Contains(*this),
11171cb0ef41Sopenharmony_ci                IsAligned(raw_instruction_start(), kCodeAlignment));
11181cb0ef41Sopenharmony_ci  if (V8_EXTERNAL_CODE_SPACE_BOOL) {
11191cb0ef41Sopenharmony_ci    CHECK_EQ(*this, code_data_container(kAcquireLoad).code());
11201cb0ef41Sopenharmony_ci  }
11211cb0ef41Sopenharmony_ci  // TODO(delphick): Refactor Factory::CodeBuilder::BuildInternal, so that the
11221cb0ef41Sopenharmony_ci  // following CHECK works builtin trampolines. It currently fails because
11231cb0ef41Sopenharmony_ci  // CodeVerify is called halfway through constructing the trampoline and so not
11241cb0ef41Sopenharmony_ci  // everything is set up.
11251cb0ef41Sopenharmony_ci  // CHECK_EQ(ReadOnlyHeap::Contains(*this), !IsExecutable());
11261cb0ef41Sopenharmony_ci  relocation_info().ObjectVerify(isolate);
11271cb0ef41Sopenharmony_ci  CHECK(V8_ENABLE_THIRD_PARTY_HEAP_BOOL ||
11281cb0ef41Sopenharmony_ci        CodeSize() <= MemoryChunkLayout::MaxRegularCodeObjectSize() ||
11291cb0ef41Sopenharmony_ci        isolate->heap()->InSpace(*this, CODE_LO_SPACE));
11301cb0ef41Sopenharmony_ci  Address last_gc_pc = kNullAddress;
11311cb0ef41Sopenharmony_ci
11321cb0ef41Sopenharmony_ci  for (RelocIterator it(*this); !it.done(); it.next()) {
11331cb0ef41Sopenharmony_ci    it.rinfo()->Verify(isolate);
11341cb0ef41Sopenharmony_ci    // Ensure that GC will not iterate twice over the same pointer.
11351cb0ef41Sopenharmony_ci    if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
11361cb0ef41Sopenharmony_ci      CHECK(it.rinfo()->pc() != last_gc_pc);
11371cb0ef41Sopenharmony_ci      last_gc_pc = it.rinfo()->pc();
11381cb0ef41Sopenharmony_ci    }
11391cb0ef41Sopenharmony_ci  }
11401cb0ef41Sopenharmony_ci}
11411cb0ef41Sopenharmony_ci
11421cb0ef41Sopenharmony_civoid JSArray::JSArrayVerify(Isolate* isolate) {
11431cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSArrayVerify(*this, isolate);
11441cb0ef41Sopenharmony_ci  // If a GC was caused while constructing this array, the elements
11451cb0ef41Sopenharmony_ci  // pointer may point to a one pointer filler map.
11461cb0ef41Sopenharmony_ci  if (!ElementsAreSafeToExamine(isolate)) return;
11471cb0ef41Sopenharmony_ci  if (elements().IsUndefined(isolate)) return;
11481cb0ef41Sopenharmony_ci  CHECK(elements().IsFixedArray() || elements().IsFixedDoubleArray());
11491cb0ef41Sopenharmony_ci  if (elements().length() == 0) {
11501cb0ef41Sopenharmony_ci    CHECK_EQ(elements(), ReadOnlyRoots(isolate).empty_fixed_array());
11511cb0ef41Sopenharmony_ci  }
11521cb0ef41Sopenharmony_ci  // Verify that the length and the elements backing store are in sync.
11531cb0ef41Sopenharmony_ci  if (length().IsSmi() &&
11541cb0ef41Sopenharmony_ci      (HasFastElements() || HasAnyNonextensibleElements())) {
11551cb0ef41Sopenharmony_ci    if (elements().length() > 0) {
11561cb0ef41Sopenharmony_ci      CHECK_IMPLIES(HasDoubleElements(), elements().IsFixedDoubleArray());
11571cb0ef41Sopenharmony_ci      CHECK_IMPLIES(HasSmiOrObjectElements() || HasAnyNonextensibleElements(),
11581cb0ef41Sopenharmony_ci                    elements().IsFixedArray());
11591cb0ef41Sopenharmony_ci    }
11601cb0ef41Sopenharmony_ci    int size = Smi::ToInt(length());
11611cb0ef41Sopenharmony_ci    // Holey / Packed backing stores might have slack or might have not been
11621cb0ef41Sopenharmony_ci    // properly initialized yet.
11631cb0ef41Sopenharmony_ci    CHECK(size <= elements().length() ||
11641cb0ef41Sopenharmony_ci          elements() == ReadOnlyRoots(isolate).empty_fixed_array());
11651cb0ef41Sopenharmony_ci  } else {
11661cb0ef41Sopenharmony_ci    CHECK(HasDictionaryElements());
11671cb0ef41Sopenharmony_ci    uint32_t array_length;
11681cb0ef41Sopenharmony_ci    CHECK(length().ToArrayLength(&array_length));
11691cb0ef41Sopenharmony_ci    if (array_length == 0xFFFFFFFF) {
11701cb0ef41Sopenharmony_ci      CHECK(length().ToArrayLength(&array_length));
11711cb0ef41Sopenharmony_ci    }
11721cb0ef41Sopenharmony_ci    if (array_length != 0) {
11731cb0ef41Sopenharmony_ci      NumberDictionary dict = NumberDictionary::cast(elements());
11741cb0ef41Sopenharmony_ci      // The dictionary can never have more elements than the array length + 1.
11751cb0ef41Sopenharmony_ci      // If the backing store grows the verification might be triggered with
11761cb0ef41Sopenharmony_ci      // the old length in place.
11771cb0ef41Sopenharmony_ci      uint32_t nof_elements = static_cast<uint32_t>(dict.NumberOfElements());
11781cb0ef41Sopenharmony_ci      if (nof_elements != 0) nof_elements--;
11791cb0ef41Sopenharmony_ci      CHECK_LE(nof_elements, array_length);
11801cb0ef41Sopenharmony_ci    }
11811cb0ef41Sopenharmony_ci  }
11821cb0ef41Sopenharmony_ci}
11831cb0ef41Sopenharmony_ci
11841cb0ef41Sopenharmony_civoid JSSet::JSSetVerify(Isolate* isolate) {
11851cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSSetVerify(*this, isolate);
11861cb0ef41Sopenharmony_ci  CHECK(table().IsOrderedHashSet() || table().IsUndefined(isolate));
11871cb0ef41Sopenharmony_ci  // TODO(arv): Verify OrderedHashTable too.
11881cb0ef41Sopenharmony_ci}
11891cb0ef41Sopenharmony_ci
11901cb0ef41Sopenharmony_civoid JSMap::JSMapVerify(Isolate* isolate) {
11911cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSMapVerify(*this, isolate);
11921cb0ef41Sopenharmony_ci  CHECK(table().IsOrderedHashMap() || table().IsUndefined(isolate));
11931cb0ef41Sopenharmony_ci  // TODO(arv): Verify OrderedHashTable too.
11941cb0ef41Sopenharmony_ci}
11951cb0ef41Sopenharmony_ci
11961cb0ef41Sopenharmony_civoid JSSetIterator::JSSetIteratorVerify(Isolate* isolate) {
11971cb0ef41Sopenharmony_ci  CHECK(IsJSSetIterator());
11981cb0ef41Sopenharmony_ci  JSCollectionIteratorVerify(isolate);
11991cb0ef41Sopenharmony_ci  CHECK(table().IsOrderedHashSet());
12001cb0ef41Sopenharmony_ci  CHECK(index().IsSmi());
12011cb0ef41Sopenharmony_ci}
12021cb0ef41Sopenharmony_ci
12031cb0ef41Sopenharmony_civoid JSMapIterator::JSMapIteratorVerify(Isolate* isolate) {
12041cb0ef41Sopenharmony_ci  CHECK(IsJSMapIterator());
12051cb0ef41Sopenharmony_ci  JSCollectionIteratorVerify(isolate);
12061cb0ef41Sopenharmony_ci  CHECK(table().IsOrderedHashMap());
12071cb0ef41Sopenharmony_ci  CHECK(index().IsSmi());
12081cb0ef41Sopenharmony_ci}
12091cb0ef41Sopenharmony_ci
12101cb0ef41Sopenharmony_ciUSE_TORQUE_VERIFIER(JSShadowRealm)
12111cb0ef41Sopenharmony_ciUSE_TORQUE_VERIFIER(JSWrappedFunction)
12121cb0ef41Sopenharmony_ci
12131cb0ef41Sopenharmony_civoid JSSharedStruct::JSSharedStructVerify(Isolate* isolate) {
12141cb0ef41Sopenharmony_ci  CHECK(IsJSSharedStruct());
12151cb0ef41Sopenharmony_ci  JSObjectVerify(isolate);
12161cb0ef41Sopenharmony_ci  CHECK(HasFastProperties());
12171cb0ef41Sopenharmony_ci  // Shared structs can only point to primitives or other shared HeapObjects,
12181cb0ef41Sopenharmony_ci  // even internally.
12191cb0ef41Sopenharmony_ci  // TODO(v8:12547): Generalize shared -> shared pointer verification.
12201cb0ef41Sopenharmony_ci  Map struct_map = map();
12211cb0ef41Sopenharmony_ci  CHECK(struct_map.InSharedHeap());
12221cb0ef41Sopenharmony_ci  CHECK(struct_map.GetBackPointer().IsUndefined(isolate));
12231cb0ef41Sopenharmony_ci  Object maybe_cell = struct_map.prototype_validity_cell();
12241cb0ef41Sopenharmony_ci  if (maybe_cell.IsCell()) CHECK(maybe_cell.InSharedHeap());
12251cb0ef41Sopenharmony_ci  CHECK(!struct_map.is_extensible());
12261cb0ef41Sopenharmony_ci  CHECK(!struct_map.is_prototype_map());
12271cb0ef41Sopenharmony_ci  CHECK(property_array().InSharedHeap());
12281cb0ef41Sopenharmony_ci  DescriptorArray descriptors = struct_map.instance_descriptors(isolate);
12291cb0ef41Sopenharmony_ci  CHECK(descriptors.InSharedHeap());
12301cb0ef41Sopenharmony_ci  for (InternalIndex i : struct_map.IterateOwnDescriptors()) {
12311cb0ef41Sopenharmony_ci    PropertyDetails details = descriptors.GetDetails(i);
12321cb0ef41Sopenharmony_ci    CHECK_EQ(PropertyKind::kData, details.kind());
12331cb0ef41Sopenharmony_ci    CHECK_EQ(PropertyLocation::kField, details.location());
12341cb0ef41Sopenharmony_ci    CHECK(details.representation().IsTagged());
12351cb0ef41Sopenharmony_ci    CHECK(
12361cb0ef41Sopenharmony_ci        RawFastPropertyAt(FieldIndex::ForDescriptor(struct_map, i)).IsShared());
12371cb0ef41Sopenharmony_ci  }
12381cb0ef41Sopenharmony_ci}
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_civoid WeakCell::WeakCellVerify(Isolate* isolate) {
12411cb0ef41Sopenharmony_ci  CHECK(IsWeakCell());
12421cb0ef41Sopenharmony_ci
12431cb0ef41Sopenharmony_ci  CHECK(target().IsUndefined(isolate) || target().CanBeHeldWeakly());
12441cb0ef41Sopenharmony_ci
12451cb0ef41Sopenharmony_ci  CHECK(prev().IsWeakCell() || prev().IsUndefined(isolate));
12461cb0ef41Sopenharmony_ci  if (prev().IsWeakCell()) {
12471cb0ef41Sopenharmony_ci    CHECK_EQ(WeakCell::cast(prev()).next(), *this);
12481cb0ef41Sopenharmony_ci  }
12491cb0ef41Sopenharmony_ci
12501cb0ef41Sopenharmony_ci  CHECK(next().IsWeakCell() || next().IsUndefined(isolate));
12511cb0ef41Sopenharmony_ci  if (next().IsWeakCell()) {
12521cb0ef41Sopenharmony_ci    CHECK_EQ(WeakCell::cast(next()).prev(), *this);
12531cb0ef41Sopenharmony_ci  }
12541cb0ef41Sopenharmony_ci
12551cb0ef41Sopenharmony_ci  CHECK_IMPLIES(unregister_token().IsUndefined(isolate),
12561cb0ef41Sopenharmony_ci                key_list_prev().IsUndefined(isolate));
12571cb0ef41Sopenharmony_ci  CHECK_IMPLIES(unregister_token().IsUndefined(isolate),
12581cb0ef41Sopenharmony_ci                key_list_next().IsUndefined(isolate));
12591cb0ef41Sopenharmony_ci
12601cb0ef41Sopenharmony_ci  CHECK(key_list_prev().IsWeakCell() || key_list_prev().IsUndefined(isolate));
12611cb0ef41Sopenharmony_ci
12621cb0ef41Sopenharmony_ci  CHECK(key_list_next().IsWeakCell() || key_list_next().IsUndefined(isolate));
12631cb0ef41Sopenharmony_ci
12641cb0ef41Sopenharmony_ci  CHECK(finalization_registry().IsUndefined(isolate) ||
12651cb0ef41Sopenharmony_ci        finalization_registry().IsJSFinalizationRegistry());
12661cb0ef41Sopenharmony_ci}
12671cb0ef41Sopenharmony_ci
12681cb0ef41Sopenharmony_civoid JSWeakRef::JSWeakRefVerify(Isolate* isolate) {
12691cb0ef41Sopenharmony_ci  CHECK(IsJSWeakRef());
12701cb0ef41Sopenharmony_ci  JSObjectVerify(isolate);
12711cb0ef41Sopenharmony_ci  CHECK(target().IsUndefined(isolate) || target().CanBeHeldWeakly());
12721cb0ef41Sopenharmony_ci}
12731cb0ef41Sopenharmony_ci
12741cb0ef41Sopenharmony_civoid JSFinalizationRegistry::JSFinalizationRegistryVerify(Isolate* isolate) {
12751cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSFinalizationRegistryVerify(*this, isolate);
12761cb0ef41Sopenharmony_ci  if (active_cells().IsWeakCell()) {
12771cb0ef41Sopenharmony_ci    CHECK(WeakCell::cast(active_cells()).prev().IsUndefined(isolate));
12781cb0ef41Sopenharmony_ci  }
12791cb0ef41Sopenharmony_ci  if (cleared_cells().IsWeakCell()) {
12801cb0ef41Sopenharmony_ci    CHECK(WeakCell::cast(cleared_cells()).prev().IsUndefined(isolate));
12811cb0ef41Sopenharmony_ci  }
12821cb0ef41Sopenharmony_ci}
12831cb0ef41Sopenharmony_ci
12841cb0ef41Sopenharmony_civoid JSWeakMap::JSWeakMapVerify(Isolate* isolate) {
12851cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSWeakMapVerify(*this, isolate);
12861cb0ef41Sopenharmony_ci  CHECK(table().IsEphemeronHashTable() || table().IsUndefined(isolate));
12871cb0ef41Sopenharmony_ci}
12881cb0ef41Sopenharmony_ci
12891cb0ef41Sopenharmony_civoid JSArrayIterator::JSArrayIteratorVerify(Isolate* isolate) {
12901cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSArrayIteratorVerify(*this, isolate);
12911cb0ef41Sopenharmony_ci
12921cb0ef41Sopenharmony_ci  CHECK_GE(next_index().Number(), 0);
12931cb0ef41Sopenharmony_ci  CHECK_LE(next_index().Number(), kMaxSafeInteger);
12941cb0ef41Sopenharmony_ci
12951cb0ef41Sopenharmony_ci  if (iterated_object().IsJSTypedArray()) {
12961cb0ef41Sopenharmony_ci    // JSTypedArray::length is limited to Smi range.
12971cb0ef41Sopenharmony_ci    CHECK(next_index().IsSmi());
12981cb0ef41Sopenharmony_ci    CHECK_LE(next_index().Number(), Smi::kMaxValue);
12991cb0ef41Sopenharmony_ci  } else if (iterated_object().IsJSArray()) {
13001cb0ef41Sopenharmony_ci    // JSArray::length is limited to Uint32 range.
13011cb0ef41Sopenharmony_ci    CHECK_LE(next_index().Number(), kMaxUInt32);
13021cb0ef41Sopenharmony_ci  }
13031cb0ef41Sopenharmony_ci}
13041cb0ef41Sopenharmony_ci
13051cb0ef41Sopenharmony_civoid JSStringIterator::JSStringIteratorVerify(Isolate* isolate) {
13061cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSStringIteratorVerify(*this, isolate);
13071cb0ef41Sopenharmony_ci  CHECK_GE(index(), 0);
13081cb0ef41Sopenharmony_ci  CHECK_LE(index(), String::kMaxLength);
13091cb0ef41Sopenharmony_ci}
13101cb0ef41Sopenharmony_ci
13111cb0ef41Sopenharmony_civoid JSWeakSet::JSWeakSetVerify(Isolate* isolate) {
13121cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSWeakSetVerify(*this, isolate);
13131cb0ef41Sopenharmony_ci  CHECK(table().IsEphemeronHashTable() || table().IsUndefined(isolate));
13141cb0ef41Sopenharmony_ci}
13151cb0ef41Sopenharmony_ci
13161cb0ef41Sopenharmony_civoid CallableTask::CallableTaskVerify(Isolate* isolate) {
13171cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::CallableTaskVerify(*this, isolate);
13181cb0ef41Sopenharmony_ci  CHECK(callable().IsCallable());
13191cb0ef41Sopenharmony_ci}
13201cb0ef41Sopenharmony_ci
13211cb0ef41Sopenharmony_civoid JSPromise::JSPromiseVerify(Isolate* isolate) {
13221cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSPromiseVerify(*this, isolate);
13231cb0ef41Sopenharmony_ci  if (status() == Promise::kPending) {
13241cb0ef41Sopenharmony_ci    CHECK(reactions().IsSmi() || reactions().IsPromiseReaction());
13251cb0ef41Sopenharmony_ci  }
13261cb0ef41Sopenharmony_ci}
13271cb0ef41Sopenharmony_ci
13281cb0ef41Sopenharmony_citemplate <typename Derived>
13291cb0ef41Sopenharmony_civoid SmallOrderedHashTable<Derived>::SmallOrderedHashTableVerify(
13301cb0ef41Sopenharmony_ci    Isolate* isolate) {
13311cb0ef41Sopenharmony_ci  CHECK(IsSmallOrderedHashTable());
13321cb0ef41Sopenharmony_ci
13331cb0ef41Sopenharmony_ci  int capacity = Capacity();
13341cb0ef41Sopenharmony_ci  CHECK_GE(capacity, kMinCapacity);
13351cb0ef41Sopenharmony_ci  CHECK_LE(capacity, kMaxCapacity);
13361cb0ef41Sopenharmony_ci
13371cb0ef41Sopenharmony_ci  for (int entry = 0; entry < NumberOfBuckets(); entry++) {
13381cb0ef41Sopenharmony_ci    int bucket = GetFirstEntry(entry);
13391cb0ef41Sopenharmony_ci    if (bucket == kNotFound) continue;
13401cb0ef41Sopenharmony_ci    CHECK_GE(bucket, 0);
13411cb0ef41Sopenharmony_ci    CHECK_LE(bucket, capacity);
13421cb0ef41Sopenharmony_ci  }
13431cb0ef41Sopenharmony_ci
13441cb0ef41Sopenharmony_ci  for (int entry = 0; entry < NumberOfElements(); entry++) {
13451cb0ef41Sopenharmony_ci    int chain = GetNextEntry(entry);
13461cb0ef41Sopenharmony_ci    if (chain == kNotFound) continue;
13471cb0ef41Sopenharmony_ci    CHECK_GE(chain, 0);
13481cb0ef41Sopenharmony_ci    CHECK_LE(chain, capacity);
13491cb0ef41Sopenharmony_ci  }
13501cb0ef41Sopenharmony_ci
13511cb0ef41Sopenharmony_ci  for (int entry = 0; entry < NumberOfElements(); entry++) {
13521cb0ef41Sopenharmony_ci    for (int offset = 0; offset < Derived::kEntrySize; offset++) {
13531cb0ef41Sopenharmony_ci      Object val = GetDataEntry(entry, offset);
13541cb0ef41Sopenharmony_ci      VerifyPointer(isolate, val);
13551cb0ef41Sopenharmony_ci    }
13561cb0ef41Sopenharmony_ci  }
13571cb0ef41Sopenharmony_ci
13581cb0ef41Sopenharmony_ci  for (int entry = NumberOfElements() + NumberOfDeletedElements();
13591cb0ef41Sopenharmony_ci       entry < Capacity(); entry++) {
13601cb0ef41Sopenharmony_ci    for (int offset = 0; offset < Derived::kEntrySize; offset++) {
13611cb0ef41Sopenharmony_ci      Object val = GetDataEntry(entry, offset);
13621cb0ef41Sopenharmony_ci      CHECK(val.IsTheHole(isolate));
13631cb0ef41Sopenharmony_ci    }
13641cb0ef41Sopenharmony_ci  }
13651cb0ef41Sopenharmony_ci}
13661cb0ef41Sopenharmony_ci
13671cb0ef41Sopenharmony_civoid SmallOrderedHashMap::SmallOrderedHashMapVerify(Isolate* isolate) {
13681cb0ef41Sopenharmony_ci  CHECK(IsSmallOrderedHashMap());
13691cb0ef41Sopenharmony_ci  SmallOrderedHashTable<SmallOrderedHashMap>::SmallOrderedHashTableVerify(
13701cb0ef41Sopenharmony_ci      isolate);
13711cb0ef41Sopenharmony_ci  for (int entry = NumberOfElements(); entry < NumberOfDeletedElements();
13721cb0ef41Sopenharmony_ci       entry++) {
13731cb0ef41Sopenharmony_ci    for (int offset = 0; offset < kEntrySize; offset++) {
13741cb0ef41Sopenharmony_ci      Object val = GetDataEntry(entry, offset);
13751cb0ef41Sopenharmony_ci      CHECK(val.IsTheHole(isolate));
13761cb0ef41Sopenharmony_ci    }
13771cb0ef41Sopenharmony_ci  }
13781cb0ef41Sopenharmony_ci}
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_civoid SmallOrderedHashSet::SmallOrderedHashSetVerify(Isolate* isolate) {
13811cb0ef41Sopenharmony_ci  CHECK(IsSmallOrderedHashSet());
13821cb0ef41Sopenharmony_ci  SmallOrderedHashTable<SmallOrderedHashSet>::SmallOrderedHashTableVerify(
13831cb0ef41Sopenharmony_ci      isolate);
13841cb0ef41Sopenharmony_ci  for (int entry = NumberOfElements(); entry < NumberOfDeletedElements();
13851cb0ef41Sopenharmony_ci       entry++) {
13861cb0ef41Sopenharmony_ci    for (int offset = 0; offset < kEntrySize; offset++) {
13871cb0ef41Sopenharmony_ci      Object val = GetDataEntry(entry, offset);
13881cb0ef41Sopenharmony_ci      CHECK(val.IsTheHole(isolate));
13891cb0ef41Sopenharmony_ci    }
13901cb0ef41Sopenharmony_ci  }
13911cb0ef41Sopenharmony_ci}
13921cb0ef41Sopenharmony_ci
13931cb0ef41Sopenharmony_civoid SmallOrderedNameDictionary::SmallOrderedNameDictionaryVerify(
13941cb0ef41Sopenharmony_ci    Isolate* isolate) {
13951cb0ef41Sopenharmony_ci  CHECK(IsSmallOrderedNameDictionary());
13961cb0ef41Sopenharmony_ci  SmallOrderedHashTable<
13971cb0ef41Sopenharmony_ci      SmallOrderedNameDictionary>::SmallOrderedHashTableVerify(isolate);
13981cb0ef41Sopenharmony_ci  for (int entry = NumberOfElements(); entry < NumberOfDeletedElements();
13991cb0ef41Sopenharmony_ci       entry++) {
14001cb0ef41Sopenharmony_ci    for (int offset = 0; offset < kEntrySize; offset++) {
14011cb0ef41Sopenharmony_ci      Object val = GetDataEntry(entry, offset);
14021cb0ef41Sopenharmony_ci      CHECK(val.IsTheHole(isolate) ||
14031cb0ef41Sopenharmony_ci            (PropertyDetails::Empty().AsSmi() == Smi::cast(val)));
14041cb0ef41Sopenharmony_ci    }
14051cb0ef41Sopenharmony_ci  }
14061cb0ef41Sopenharmony_ci}
14071cb0ef41Sopenharmony_ci
14081cb0ef41Sopenharmony_civoid SwissNameDictionary::SwissNameDictionaryVerify(Isolate* isolate) {
14091cb0ef41Sopenharmony_ci  this->SwissNameDictionaryVerify(isolate, false);
14101cb0ef41Sopenharmony_ci}
14111cb0ef41Sopenharmony_ci
14121cb0ef41Sopenharmony_civoid SwissNameDictionary::SwissNameDictionaryVerify(Isolate* isolate,
14131cb0ef41Sopenharmony_ci                                                    bool slow_checks) {
14141cb0ef41Sopenharmony_ci  DisallowHeapAllocation no_gc;
14151cb0ef41Sopenharmony_ci
14161cb0ef41Sopenharmony_ci  CHECK(IsValidCapacity(Capacity()));
14171cb0ef41Sopenharmony_ci
14181cb0ef41Sopenharmony_ci  meta_table().ByteArrayVerify(isolate);
14191cb0ef41Sopenharmony_ci
14201cb0ef41Sopenharmony_ci  int seen_deleted = 0;
14211cb0ef41Sopenharmony_ci  int seen_present = 0;
14221cb0ef41Sopenharmony_ci
14231cb0ef41Sopenharmony_ci  for (int i = 0; i < Capacity(); i++) {
14241cb0ef41Sopenharmony_ci    ctrl_t ctrl = GetCtrl(i);
14251cb0ef41Sopenharmony_ci
14261cb0ef41Sopenharmony_ci    if (IsFull(ctrl) || slow_checks) {
14271cb0ef41Sopenharmony_ci      Object key = KeyAt(i);
14281cb0ef41Sopenharmony_ci      Object value = ValueAtRaw(i);
14291cb0ef41Sopenharmony_ci
14301cb0ef41Sopenharmony_ci      if (IsFull(ctrl)) {
14311cb0ef41Sopenharmony_ci        ++seen_present;
14321cb0ef41Sopenharmony_ci
14331cb0ef41Sopenharmony_ci        Name name = Name::cast(key);
14341cb0ef41Sopenharmony_ci        if (slow_checks) {
14351cb0ef41Sopenharmony_ci          CHECK_EQ(swiss_table::H2(name.hash()), ctrl);
14361cb0ef41Sopenharmony_ci        }
14371cb0ef41Sopenharmony_ci
14381cb0ef41Sopenharmony_ci        CHECK(!key.IsTheHole());
14391cb0ef41Sopenharmony_ci        CHECK(!value.IsTheHole());
14401cb0ef41Sopenharmony_ci        name.NameVerify(isolate);
14411cb0ef41Sopenharmony_ci        value.ObjectVerify(isolate);
14421cb0ef41Sopenharmony_ci      } else if (IsDeleted(ctrl)) {
14431cb0ef41Sopenharmony_ci        ++seen_deleted;
14441cb0ef41Sopenharmony_ci        CHECK(key.IsTheHole());
14451cb0ef41Sopenharmony_ci        CHECK(value.IsTheHole());
14461cb0ef41Sopenharmony_ci      } else if (IsEmpty(ctrl)) {
14471cb0ef41Sopenharmony_ci        CHECK(key.IsTheHole());
14481cb0ef41Sopenharmony_ci        CHECK(value.IsTheHole());
14491cb0ef41Sopenharmony_ci      } else {
14501cb0ef41Sopenharmony_ci        // Something unexpected. Note that we don't use kSentinel at the moment.
14511cb0ef41Sopenharmony_ci        UNREACHABLE();
14521cb0ef41Sopenharmony_ci      }
14531cb0ef41Sopenharmony_ci    }
14541cb0ef41Sopenharmony_ci  }
14551cb0ef41Sopenharmony_ci
14561cb0ef41Sopenharmony_ci  CHECK_EQ(seen_present, NumberOfElements());
14571cb0ef41Sopenharmony_ci  if (slow_checks) {
14581cb0ef41Sopenharmony_ci    CHECK_EQ(seen_deleted, NumberOfDeletedElements());
14591cb0ef41Sopenharmony_ci
14601cb0ef41Sopenharmony_ci    // Verify copy of first group at end (= after Capacity() slots) of control
14611cb0ef41Sopenharmony_ci    // table.
14621cb0ef41Sopenharmony_ci    for (int i = 0; i < std::min(static_cast<int>(Group::kWidth), Capacity());
14631cb0ef41Sopenharmony_ci         ++i) {
14641cb0ef41Sopenharmony_ci      CHECK_EQ(CtrlTable()[i], CtrlTable()[Capacity() + i]);
14651cb0ef41Sopenharmony_ci    }
14661cb0ef41Sopenharmony_ci    // If 2 * capacity is smaller than the capacity plus group width, the slots
14671cb0ef41Sopenharmony_ci    // after that must be empty.
14681cb0ef41Sopenharmony_ci    for (int i = 2 * Capacity(); i < Capacity() + kGroupWidth; ++i) {
14691cb0ef41Sopenharmony_ci      CHECK_EQ(Ctrl::kEmpty, CtrlTable()[i]);
14701cb0ef41Sopenharmony_ci    }
14711cb0ef41Sopenharmony_ci
14721cb0ef41Sopenharmony_ci    for (int enum_index = 0; enum_index < UsedCapacity(); ++enum_index) {
14731cb0ef41Sopenharmony_ci      int entry = EntryForEnumerationIndex(enum_index);
14741cb0ef41Sopenharmony_ci      CHECK_LT(entry, Capacity());
14751cb0ef41Sopenharmony_ci      ctrl_t ctrl = GetCtrl(entry);
14761cb0ef41Sopenharmony_ci
14771cb0ef41Sopenharmony_ci      // Enum table must not point to empty slots.
14781cb0ef41Sopenharmony_ci      CHECK(IsFull(ctrl) || IsDeleted(ctrl));
14791cb0ef41Sopenharmony_ci    }
14801cb0ef41Sopenharmony_ci  }
14811cb0ef41Sopenharmony_ci}
14821cb0ef41Sopenharmony_ci
14831cb0ef41Sopenharmony_civoid JSRegExp::JSRegExpVerify(Isolate* isolate) {
14841cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSRegExpVerify(*this, isolate);
14851cb0ef41Sopenharmony_ci  switch (type_tag()) {
14861cb0ef41Sopenharmony_ci    case JSRegExp::ATOM: {
14871cb0ef41Sopenharmony_ci      FixedArray arr = FixedArray::cast(data());
14881cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kAtomPatternIndex).IsString());
14891cb0ef41Sopenharmony_ci      break;
14901cb0ef41Sopenharmony_ci    }
14911cb0ef41Sopenharmony_ci    case JSRegExp::EXPERIMENTAL: {
14921cb0ef41Sopenharmony_ci      FixedArray arr = FixedArray::cast(data());
14931cb0ef41Sopenharmony_ci      Smi uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci      Object latin1_code = arr.get(JSRegExp::kIrregexpLatin1CodeIndex);
14961cb0ef41Sopenharmony_ci      Object uc16_code = arr.get(JSRegExp::kIrregexpUC16CodeIndex);
14971cb0ef41Sopenharmony_ci      Object latin1_bytecode = arr.get(JSRegExp::kIrregexpLatin1BytecodeIndex);
14981cb0ef41Sopenharmony_ci      Object uc16_bytecode = arr.get(JSRegExp::kIrregexpUC16BytecodeIndex);
14991cb0ef41Sopenharmony_ci
15001cb0ef41Sopenharmony_ci      bool is_compiled = latin1_code.IsCodeT();
15011cb0ef41Sopenharmony_ci      if (is_compiled) {
15021cb0ef41Sopenharmony_ci        CHECK_EQ(FromCodeT(CodeT::cast(latin1_code)).builtin_id(),
15031cb0ef41Sopenharmony_ci                 Builtin::kRegExpExperimentalTrampoline);
15041cb0ef41Sopenharmony_ci        CHECK_EQ(uc16_code, latin1_code);
15051cb0ef41Sopenharmony_ci
15061cb0ef41Sopenharmony_ci        CHECK(latin1_bytecode.IsByteArray());
15071cb0ef41Sopenharmony_ci        CHECK_EQ(uc16_bytecode, latin1_bytecode);
15081cb0ef41Sopenharmony_ci      } else {
15091cb0ef41Sopenharmony_ci        CHECK_EQ(latin1_code, uninitialized);
15101cb0ef41Sopenharmony_ci        CHECK_EQ(uc16_code, uninitialized);
15111cb0ef41Sopenharmony_ci
15121cb0ef41Sopenharmony_ci        CHECK_EQ(latin1_bytecode, uninitialized);
15131cb0ef41Sopenharmony_ci        CHECK_EQ(uc16_bytecode, uninitialized);
15141cb0ef41Sopenharmony_ci      }
15151cb0ef41Sopenharmony_ci
15161cb0ef41Sopenharmony_ci      CHECK_EQ(arr.get(JSRegExp::kIrregexpMaxRegisterCountIndex),
15171cb0ef41Sopenharmony_ci               uninitialized);
15181cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kIrregexpCaptureCountIndex).IsSmi());
15191cb0ef41Sopenharmony_ci      CHECK_GE(Smi::ToInt(arr.get(JSRegExp::kIrregexpCaptureCountIndex)), 0);
15201cb0ef41Sopenharmony_ci      CHECK_EQ(arr.get(JSRegExp::kIrregexpTicksUntilTierUpIndex),
15211cb0ef41Sopenharmony_ci               uninitialized);
15221cb0ef41Sopenharmony_ci      CHECK_EQ(arr.get(JSRegExp::kIrregexpBacktrackLimit), uninitialized);
15231cb0ef41Sopenharmony_ci      break;
15241cb0ef41Sopenharmony_ci    }
15251cb0ef41Sopenharmony_ci    case JSRegExp::IRREGEXP: {
15261cb0ef41Sopenharmony_ci      bool can_be_interpreted = RegExp::CanGenerateBytecode();
15271cb0ef41Sopenharmony_ci
15281cb0ef41Sopenharmony_ci      FixedArray arr = FixedArray::cast(data());
15291cb0ef41Sopenharmony_ci      Object one_byte_data = arr.get(JSRegExp::kIrregexpLatin1CodeIndex);
15301cb0ef41Sopenharmony_ci      // Smi : Not compiled yet (-1).
15311cb0ef41Sopenharmony_ci      // Code: Compiled irregexp code or trampoline to the interpreter.
15321cb0ef41Sopenharmony_ci      CHECK((one_byte_data.IsSmi() &&
15331cb0ef41Sopenharmony_ci             Smi::ToInt(one_byte_data) == JSRegExp::kUninitializedValue) ||
15341cb0ef41Sopenharmony_ci            one_byte_data.IsCodeT());
15351cb0ef41Sopenharmony_ci      Object uc16_data = arr.get(JSRegExp::kIrregexpUC16CodeIndex);
15361cb0ef41Sopenharmony_ci      CHECK((uc16_data.IsSmi() &&
15371cb0ef41Sopenharmony_ci             Smi::ToInt(uc16_data) == JSRegExp::kUninitializedValue) ||
15381cb0ef41Sopenharmony_ci            uc16_data.IsCodeT());
15391cb0ef41Sopenharmony_ci
15401cb0ef41Sopenharmony_ci      Object one_byte_bytecode =
15411cb0ef41Sopenharmony_ci          arr.get(JSRegExp::kIrregexpLatin1BytecodeIndex);
15421cb0ef41Sopenharmony_ci      // Smi : Not compiled yet (-1).
15431cb0ef41Sopenharmony_ci      // ByteArray: Bytecode to interpret regexp.
15441cb0ef41Sopenharmony_ci      CHECK((one_byte_bytecode.IsSmi() &&
15451cb0ef41Sopenharmony_ci             Smi::ToInt(one_byte_bytecode) == JSRegExp::kUninitializedValue) ||
15461cb0ef41Sopenharmony_ci            (can_be_interpreted && one_byte_bytecode.IsByteArray()));
15471cb0ef41Sopenharmony_ci      Object uc16_bytecode = arr.get(JSRegExp::kIrregexpUC16BytecodeIndex);
15481cb0ef41Sopenharmony_ci      CHECK((uc16_bytecode.IsSmi() &&
15491cb0ef41Sopenharmony_ci             Smi::ToInt(uc16_bytecode) == JSRegExp::kUninitializedValue) ||
15501cb0ef41Sopenharmony_ci            (can_be_interpreted && uc16_bytecode.IsByteArray()));
15511cb0ef41Sopenharmony_ci
15521cb0ef41Sopenharmony_ci      CHECK_IMPLIES(one_byte_data.IsSmi(), one_byte_bytecode.IsSmi());
15531cb0ef41Sopenharmony_ci      CHECK_IMPLIES(uc16_data.IsSmi(), uc16_bytecode.IsSmi());
15541cb0ef41Sopenharmony_ci
15551cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kIrregexpCaptureCountIndex).IsSmi());
15561cb0ef41Sopenharmony_ci      CHECK_GE(Smi::ToInt(arr.get(JSRegExp::kIrregexpCaptureCountIndex)), 0);
15571cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kIrregexpMaxRegisterCountIndex).IsSmi());
15581cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kIrregexpTicksUntilTierUpIndex).IsSmi());
15591cb0ef41Sopenharmony_ci      CHECK(arr.get(JSRegExp::kIrregexpBacktrackLimit).IsSmi());
15601cb0ef41Sopenharmony_ci      break;
15611cb0ef41Sopenharmony_ci    }
15621cb0ef41Sopenharmony_ci    default:
15631cb0ef41Sopenharmony_ci      CHECK_EQ(JSRegExp::NOT_COMPILED, type_tag());
15641cb0ef41Sopenharmony_ci      CHECK(data().IsUndefined(isolate));
15651cb0ef41Sopenharmony_ci      break;
15661cb0ef41Sopenharmony_ci  }
15671cb0ef41Sopenharmony_ci}
15681cb0ef41Sopenharmony_ci
15691cb0ef41Sopenharmony_civoid JSProxy::JSProxyVerify(Isolate* isolate) {
15701cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSProxyVerify(*this, isolate);
15711cb0ef41Sopenharmony_ci  CHECK(map().GetConstructor().IsJSFunction());
15721cb0ef41Sopenharmony_ci  if (!IsRevoked()) {
15731cb0ef41Sopenharmony_ci    CHECK_EQ(target().IsCallable(), map().is_callable());
15741cb0ef41Sopenharmony_ci    CHECK_EQ(target().IsConstructor(), map().is_constructor());
15751cb0ef41Sopenharmony_ci  }
15761cb0ef41Sopenharmony_ci  CHECK(map().prototype().IsNull(isolate));
15771cb0ef41Sopenharmony_ci  // There should be no properties on a Proxy.
15781cb0ef41Sopenharmony_ci  CHECK_EQ(0, map().NumberOfOwnDescriptors());
15791cb0ef41Sopenharmony_ci}
15801cb0ef41Sopenharmony_ci
15811cb0ef41Sopenharmony_civoid JSArrayBuffer::JSArrayBufferVerify(Isolate* isolate) {
15821cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSArrayBufferVerify(*this, isolate);
15831cb0ef41Sopenharmony_ci  if (FIELD_SIZE(kOptionalPaddingOffset) != 0) {
15841cb0ef41Sopenharmony_ci    CHECK_EQ(4, FIELD_SIZE(kOptionalPaddingOffset));
15851cb0ef41Sopenharmony_ci    CHECK_EQ(0,
15861cb0ef41Sopenharmony_ci             *reinterpret_cast<uint32_t*>(address() + kOptionalPaddingOffset));
15871cb0ef41Sopenharmony_ci  }
15881cb0ef41Sopenharmony_ci}
15891cb0ef41Sopenharmony_ci
15901cb0ef41Sopenharmony_civoid JSArrayBufferView::JSArrayBufferViewVerify(Isolate* isolate) {
15911cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSArrayBufferViewVerify(*this, isolate);
15921cb0ef41Sopenharmony_ci  CHECK_LE(byte_length(), JSArrayBuffer::kMaxByteLength);
15931cb0ef41Sopenharmony_ci  CHECK_LE(byte_offset(), JSArrayBuffer::kMaxByteLength);
15941cb0ef41Sopenharmony_ci}
15951cb0ef41Sopenharmony_ci
15961cb0ef41Sopenharmony_civoid JSTypedArray::JSTypedArrayVerify(Isolate* isolate) {
15971cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSTypedArrayVerify(*this, isolate);
15981cb0ef41Sopenharmony_ci  CHECK_LE(GetLength(), JSTypedArray::kMaxLength);
15991cb0ef41Sopenharmony_ci}
16001cb0ef41Sopenharmony_ci
16011cb0ef41Sopenharmony_civoid JSDataView::JSDataViewVerify(Isolate* isolate) {
16021cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::JSDataViewVerify(*this, isolate);
16031cb0ef41Sopenharmony_ci  if (!WasDetached()) {
16041cb0ef41Sopenharmony_ci    CHECK_EQ(reinterpret_cast<uint8_t*>(
16051cb0ef41Sopenharmony_ci                 JSArrayBuffer::cast(buffer()).backing_store()) +
16061cb0ef41Sopenharmony_ci                 byte_offset(),
16071cb0ef41Sopenharmony_ci             data_pointer());
16081cb0ef41Sopenharmony_ci  }
16091cb0ef41Sopenharmony_ci}
16101cb0ef41Sopenharmony_ci
16111cb0ef41Sopenharmony_civoid AsyncGeneratorRequest::AsyncGeneratorRequestVerify(Isolate* isolate) {
16121cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::AsyncGeneratorRequestVerify(*this, isolate);
16131cb0ef41Sopenharmony_ci  CHECK_GE(resume_mode(), JSGeneratorObject::kNext);
16141cb0ef41Sopenharmony_ci  CHECK_LE(resume_mode(), JSGeneratorObject::kThrow);
16151cb0ef41Sopenharmony_ci}
16161cb0ef41Sopenharmony_ci
16171cb0ef41Sopenharmony_civoid BigIntBase::BigIntBaseVerify(Isolate* isolate) {
16181cb0ef41Sopenharmony_ci  CHECK_GE(length(), 0);
16191cb0ef41Sopenharmony_ci  CHECK_IMPLIES(is_zero(), !sign());  // There is no -0n.
16201cb0ef41Sopenharmony_ci}
16211cb0ef41Sopenharmony_ci
16221cb0ef41Sopenharmony_civoid SourceTextModuleInfoEntry::SourceTextModuleInfoEntryVerify(
16231cb0ef41Sopenharmony_ci    Isolate* isolate) {
16241cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::SourceTextModuleInfoEntryVerify(*this,
16251cb0ef41Sopenharmony_ci                                                                 isolate);
16261cb0ef41Sopenharmony_ci  CHECK_IMPLIES(import_name().IsString(), module_request() >= 0);
16271cb0ef41Sopenharmony_ci  CHECK_IMPLIES(export_name().IsString() && import_name().IsString(),
16281cb0ef41Sopenharmony_ci                local_name().IsUndefined(isolate));
16291cb0ef41Sopenharmony_ci}
16301cb0ef41Sopenharmony_ci
16311cb0ef41Sopenharmony_civoid Module::ModuleVerify(Isolate* isolate) {
16321cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ModuleVerify(*this, isolate);
16331cb0ef41Sopenharmony_ci
16341cb0ef41Sopenharmony_ci  CHECK_EQ(status() == Module::kErrored, !exception().IsTheHole(isolate));
16351cb0ef41Sopenharmony_ci
16361cb0ef41Sopenharmony_ci  CHECK(module_namespace().IsUndefined(isolate) ||
16371cb0ef41Sopenharmony_ci        module_namespace().IsJSModuleNamespace());
16381cb0ef41Sopenharmony_ci  if (module_namespace().IsJSModuleNamespace()) {
16391cb0ef41Sopenharmony_ci    CHECK_LE(Module::kLinking, status());
16401cb0ef41Sopenharmony_ci    CHECK_EQ(JSModuleNamespace::cast(module_namespace()).module(), *this);
16411cb0ef41Sopenharmony_ci  }
16421cb0ef41Sopenharmony_ci
16431cb0ef41Sopenharmony_ci  if (!(status() == kErrored || status() == kEvaluating ||
16441cb0ef41Sopenharmony_ci        status() == kEvaluated)) {
16451cb0ef41Sopenharmony_ci    CHECK(top_level_capability().IsUndefined());
16461cb0ef41Sopenharmony_ci  }
16471cb0ef41Sopenharmony_ci
16481cb0ef41Sopenharmony_ci  CHECK_NE(hash(), 0);
16491cb0ef41Sopenharmony_ci}
16501cb0ef41Sopenharmony_ci
16511cb0ef41Sopenharmony_civoid ModuleRequest::ModuleRequestVerify(Isolate* isolate) {
16521cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ModuleRequestVerify(*this, isolate);
16531cb0ef41Sopenharmony_ci  CHECK_EQ(0,
16541cb0ef41Sopenharmony_ci           import_assertions().length() % ModuleRequest::kAssertionEntrySize);
16551cb0ef41Sopenharmony_ci
16561cb0ef41Sopenharmony_ci  for (int i = 0; i < import_assertions().length();
16571cb0ef41Sopenharmony_ci       i += ModuleRequest::kAssertionEntrySize) {
16581cb0ef41Sopenharmony_ci    CHECK(import_assertions().get(i).IsString());      // Assertion key
16591cb0ef41Sopenharmony_ci    CHECK(import_assertions().get(i + 1).IsString());  // Assertion value
16601cb0ef41Sopenharmony_ci    CHECK(import_assertions().get(i + 2).IsSmi());     // Assertion location
16611cb0ef41Sopenharmony_ci  }
16621cb0ef41Sopenharmony_ci}
16631cb0ef41Sopenharmony_ci
16641cb0ef41Sopenharmony_civoid SourceTextModule::SourceTextModuleVerify(Isolate* isolate) {
16651cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::SourceTextModuleVerify(*this, isolate);
16661cb0ef41Sopenharmony_ci
16671cb0ef41Sopenharmony_ci  if (status() == kErrored) {
16681cb0ef41Sopenharmony_ci    CHECK(code().IsSharedFunctionInfo());
16691cb0ef41Sopenharmony_ci  } else if (status() == kEvaluating || status() == kEvaluated) {
16701cb0ef41Sopenharmony_ci    CHECK(code().IsJSGeneratorObject());
16711cb0ef41Sopenharmony_ci  } else {
16721cb0ef41Sopenharmony_ci    if (status() == kLinked) {
16731cb0ef41Sopenharmony_ci      CHECK(code().IsJSGeneratorObject());
16741cb0ef41Sopenharmony_ci    } else if (status() == kLinking) {
16751cb0ef41Sopenharmony_ci      CHECK(code().IsJSFunction());
16761cb0ef41Sopenharmony_ci    } else if (status() == kPreLinking) {
16771cb0ef41Sopenharmony_ci      CHECK(code().IsSharedFunctionInfo());
16781cb0ef41Sopenharmony_ci    } else if (status() == kUnlinked) {
16791cb0ef41Sopenharmony_ci      CHECK(code().IsSharedFunctionInfo());
16801cb0ef41Sopenharmony_ci    }
16811cb0ef41Sopenharmony_ci    CHECK(!AsyncParentModuleCount());
16821cb0ef41Sopenharmony_ci    CHECK(!pending_async_dependencies());
16831cb0ef41Sopenharmony_ci    CHECK(!IsAsyncEvaluating());
16841cb0ef41Sopenharmony_ci  }
16851cb0ef41Sopenharmony_ci
16861cb0ef41Sopenharmony_ci  CHECK_EQ(requested_modules().length(), info().module_requests().length());
16871cb0ef41Sopenharmony_ci}
16881cb0ef41Sopenharmony_ci
16891cb0ef41Sopenharmony_civoid SyntheticModule::SyntheticModuleVerify(Isolate* isolate) {
16901cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::SyntheticModuleVerify(*this, isolate);
16911cb0ef41Sopenharmony_ci
16921cb0ef41Sopenharmony_ci  for (int i = 0; i < export_names().length(); i++) {
16931cb0ef41Sopenharmony_ci    CHECK(export_names().get(i).IsString());
16941cb0ef41Sopenharmony_ci  }
16951cb0ef41Sopenharmony_ci}
16961cb0ef41Sopenharmony_ci
16971cb0ef41Sopenharmony_civoid PrototypeInfo::PrototypeInfoVerify(Isolate* isolate) {
16981cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::PrototypeInfoVerify(*this, isolate);
16991cb0ef41Sopenharmony_ci  if (prototype_users().IsWeakArrayList()) {
17001cb0ef41Sopenharmony_ci    PrototypeUsers::Verify(WeakArrayList::cast(prototype_users()));
17011cb0ef41Sopenharmony_ci  } else {
17021cb0ef41Sopenharmony_ci    CHECK(prototype_users().IsSmi());
17031cb0ef41Sopenharmony_ci  }
17041cb0ef41Sopenharmony_ci}
17051cb0ef41Sopenharmony_ci
17061cb0ef41Sopenharmony_civoid PrototypeUsers::Verify(WeakArrayList array) {
17071cb0ef41Sopenharmony_ci  if (array.length() == 0) {
17081cb0ef41Sopenharmony_ci    // Allow empty & uninitialized lists.
17091cb0ef41Sopenharmony_ci    return;
17101cb0ef41Sopenharmony_ci  }
17111cb0ef41Sopenharmony_ci  // Verify empty slot chain.
17121cb0ef41Sopenharmony_ci  int empty_slot = Smi::ToInt(empty_slot_index(array));
17131cb0ef41Sopenharmony_ci  int empty_slots_count = 0;
17141cb0ef41Sopenharmony_ci  while (empty_slot != kNoEmptySlotsMarker) {
17151cb0ef41Sopenharmony_ci    CHECK_GT(empty_slot, 0);
17161cb0ef41Sopenharmony_ci    CHECK_LT(empty_slot, array.length());
17171cb0ef41Sopenharmony_ci    empty_slot = array.Get(empty_slot).ToSmi().value();
17181cb0ef41Sopenharmony_ci    ++empty_slots_count;
17191cb0ef41Sopenharmony_ci  }
17201cb0ef41Sopenharmony_ci
17211cb0ef41Sopenharmony_ci  // Verify that all elements are either weak pointers or SMIs marking empty
17221cb0ef41Sopenharmony_ci  // slots.
17231cb0ef41Sopenharmony_ci  int weak_maps_count = 0;
17241cb0ef41Sopenharmony_ci  for (int i = kFirstIndex; i < array.length(); ++i) {
17251cb0ef41Sopenharmony_ci    HeapObject heap_object;
17261cb0ef41Sopenharmony_ci    MaybeObject object = array.Get(i);
17271cb0ef41Sopenharmony_ci    if ((object->GetHeapObjectIfWeak(&heap_object) && heap_object.IsMap()) ||
17281cb0ef41Sopenharmony_ci        object->IsCleared()) {
17291cb0ef41Sopenharmony_ci      ++weak_maps_count;
17301cb0ef41Sopenharmony_ci    } else {
17311cb0ef41Sopenharmony_ci      CHECK(object->IsSmi());
17321cb0ef41Sopenharmony_ci    }
17331cb0ef41Sopenharmony_ci  }
17341cb0ef41Sopenharmony_ci
17351cb0ef41Sopenharmony_ci  CHECK_EQ(weak_maps_count + empty_slots_count + 1, array.length());
17361cb0ef41Sopenharmony_ci}
17371cb0ef41Sopenharmony_ci
17381cb0ef41Sopenharmony_civoid EnumCache::EnumCacheVerify(Isolate* isolate) {
17391cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::EnumCacheVerify(*this, isolate);
17401cb0ef41Sopenharmony_ci  Heap* heap = isolate->heap();
17411cb0ef41Sopenharmony_ci  if (*this == ReadOnlyRoots(heap).empty_enum_cache()) {
17421cb0ef41Sopenharmony_ci    CHECK_EQ(ReadOnlyRoots(heap).empty_fixed_array(), keys());
17431cb0ef41Sopenharmony_ci    CHECK_EQ(ReadOnlyRoots(heap).empty_fixed_array(), indices());
17441cb0ef41Sopenharmony_ci  }
17451cb0ef41Sopenharmony_ci}
17461cb0ef41Sopenharmony_ci
17471cb0ef41Sopenharmony_civoid ObjectBoilerplateDescription::ObjectBoilerplateDescriptionVerify(
17481cb0ef41Sopenharmony_ci    Isolate* isolate) {
17491cb0ef41Sopenharmony_ci  CHECK(IsObjectBoilerplateDescription());
17501cb0ef41Sopenharmony_ci  CHECK_GE(this->length(),
17511cb0ef41Sopenharmony_ci           ObjectBoilerplateDescription::kDescriptionStartIndex);
17521cb0ef41Sopenharmony_ci  this->FixedArrayVerify(isolate);
17531cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); ++i) {
17541cb0ef41Sopenharmony_ci    // No ThinStrings in the boilerplate.
17551cb0ef41Sopenharmony_ci    CHECK(!get(isolate, i).IsThinString(isolate));
17561cb0ef41Sopenharmony_ci  }
17571cb0ef41Sopenharmony_ci}
17581cb0ef41Sopenharmony_ci
17591cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
17601cb0ef41Sopenharmony_ci
17611cb0ef41Sopenharmony_civoid WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) {
17621cb0ef41Sopenharmony_ci  JSObjectVerify(isolate);
17631cb0ef41Sopenharmony_ci  CHECK(IsWasmInstanceObject());
17641cb0ef41Sopenharmony_ci
17651cb0ef41Sopenharmony_ci  // Just generically check all tagged fields. Don't check the untagged fields,
17661cb0ef41Sopenharmony_ci  // as some of them might still contain the "undefined" value if the
17671cb0ef41Sopenharmony_ci  // WasmInstanceObject is not fully set up yet.
17681cb0ef41Sopenharmony_ci  for (int offset = kHeaderSize; offset < kEndOfStrongFieldsOffset;
17691cb0ef41Sopenharmony_ci       offset += kTaggedSize) {
17701cb0ef41Sopenharmony_ci    VerifyObjectField(isolate, offset);
17711cb0ef41Sopenharmony_ci  }
17721cb0ef41Sopenharmony_ci}
17731cb0ef41Sopenharmony_ci
17741cb0ef41Sopenharmony_civoid WasmValueObject::WasmValueObjectVerify(Isolate* isolate) {
17751cb0ef41Sopenharmony_ci  JSObjectVerify(isolate);
17761cb0ef41Sopenharmony_ci  CHECK(IsWasmValueObject());
17771cb0ef41Sopenharmony_ci}
17781cb0ef41Sopenharmony_ci
17791cb0ef41Sopenharmony_civoid WasmExportedFunctionData::WasmExportedFunctionDataVerify(
17801cb0ef41Sopenharmony_ci    Isolate* isolate) {
17811cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::WasmExportedFunctionDataVerify(*this, isolate);
17821cb0ef41Sopenharmony_ci  CHECK(
17831cb0ef41Sopenharmony_ci      wrapper_code().kind() == CodeKind::JS_TO_WASM_FUNCTION ||
17841cb0ef41Sopenharmony_ci      wrapper_code().kind() == CodeKind::C_WASM_ENTRY ||
17851cb0ef41Sopenharmony_ci      (wrapper_code().is_builtin() &&
17861cb0ef41Sopenharmony_ci       (wrapper_code().builtin_id() == Builtin::kGenericJSToWasmWrapper ||
17871cb0ef41Sopenharmony_ci        wrapper_code().builtin_id() == Builtin::kWasmReturnPromiseOnSuspend)));
17881cb0ef41Sopenharmony_ci}
17891cb0ef41Sopenharmony_ci
17901cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
17911cb0ef41Sopenharmony_ci
17921cb0ef41Sopenharmony_civoid DataHandler::DataHandlerVerify(Isolate* isolate) {
17931cb0ef41Sopenharmony_ci  // Don't call TorqueGeneratedClassVerifiers::DataHandlerVerify because the
17941cb0ef41Sopenharmony_ci  // Torque definition of this class includes all of the optional fields.
17951cb0ef41Sopenharmony_ci
17961cb0ef41Sopenharmony_ci  // This assertion exists to encourage updating this verification function if
17971cb0ef41Sopenharmony_ci  // new fields are added in the Torque class layout definition.
17981cb0ef41Sopenharmony_ci  STATIC_ASSERT(DataHandler::kHeaderSize == 6 * kTaggedSize);
17991cb0ef41Sopenharmony_ci
18001cb0ef41Sopenharmony_ci  StructVerify(isolate);
18011cb0ef41Sopenharmony_ci  CHECK(IsDataHandler());
18021cb0ef41Sopenharmony_ci  VerifyPointer(isolate, smi_handler(isolate));
18031cb0ef41Sopenharmony_ci  CHECK_IMPLIES(!smi_handler().IsSmi(),
18041cb0ef41Sopenharmony_ci                IsStoreHandler() && smi_handler().IsCodeT());
18051cb0ef41Sopenharmony_ci  VerifyPointer(isolate, validity_cell(isolate));
18061cb0ef41Sopenharmony_ci  CHECK(validity_cell().IsSmi() || validity_cell().IsCell());
18071cb0ef41Sopenharmony_ci  int data_count = data_field_count();
18081cb0ef41Sopenharmony_ci  if (data_count >= 1) {
18091cb0ef41Sopenharmony_ci    VerifyMaybeObjectField(isolate, kData1Offset);
18101cb0ef41Sopenharmony_ci  }
18111cb0ef41Sopenharmony_ci  if (data_count >= 2) {
18121cb0ef41Sopenharmony_ci    VerifyMaybeObjectField(isolate, kData2Offset);
18131cb0ef41Sopenharmony_ci  }
18141cb0ef41Sopenharmony_ci  if (data_count >= 3) {
18151cb0ef41Sopenharmony_ci    VerifyMaybeObjectField(isolate, kData3Offset);
18161cb0ef41Sopenharmony_ci  }
18171cb0ef41Sopenharmony_ci}
18181cb0ef41Sopenharmony_ci
18191cb0ef41Sopenharmony_civoid LoadHandler::LoadHandlerVerify(Isolate* isolate) {
18201cb0ef41Sopenharmony_ci  DataHandler::DataHandlerVerify(isolate);
18211cb0ef41Sopenharmony_ci  // TODO(ishell): check handler integrity
18221cb0ef41Sopenharmony_ci}
18231cb0ef41Sopenharmony_ci
18241cb0ef41Sopenharmony_civoid StoreHandler::StoreHandlerVerify(Isolate* isolate) {
18251cb0ef41Sopenharmony_ci  DataHandler::DataHandlerVerify(isolate);
18261cb0ef41Sopenharmony_ci  // TODO(ishell): check handler integrity
18271cb0ef41Sopenharmony_ci}
18281cb0ef41Sopenharmony_ci
18291cb0ef41Sopenharmony_civoid CallHandlerInfo::CallHandlerInfoVerify(Isolate* isolate) {
18301cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::CallHandlerInfoVerify(*this, isolate);
18311cb0ef41Sopenharmony_ci  CHECK(map() == ReadOnlyRoots(isolate).side_effect_call_handler_info_map() ||
18321cb0ef41Sopenharmony_ci        map() ==
18331cb0ef41Sopenharmony_ci            ReadOnlyRoots(isolate).side_effect_free_call_handler_info_map() ||
18341cb0ef41Sopenharmony_ci        map() == ReadOnlyRoots(isolate)
18351cb0ef41Sopenharmony_ci                     .next_call_side_effect_free_call_handler_info_map());
18361cb0ef41Sopenharmony_ci}
18371cb0ef41Sopenharmony_ci
18381cb0ef41Sopenharmony_civoid AllocationSite::AllocationSiteVerify(Isolate* isolate) {
18391cb0ef41Sopenharmony_ci  CHECK(IsAllocationSite());
18401cb0ef41Sopenharmony_ci  CHECK(dependent_code().IsDependentCode());
18411cb0ef41Sopenharmony_ci  CHECK(transition_info_or_boilerplate().IsSmi() ||
18421cb0ef41Sopenharmony_ci        transition_info_or_boilerplate().IsJSObject());
18431cb0ef41Sopenharmony_ci  CHECK(nested_site().IsAllocationSite() || nested_site() == Smi::zero());
18441cb0ef41Sopenharmony_ci}
18451cb0ef41Sopenharmony_ci
18461cb0ef41Sopenharmony_civoid Script::ScriptVerify(Isolate* isolate) {
18471cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ScriptVerify(*this, isolate);
18481cb0ef41Sopenharmony_ci  if V8_UNLIKELY (type() == Script::TYPE_WEB_SNAPSHOT) {
18491cb0ef41Sopenharmony_ci    CHECK_LE(shared_function_info_count(), shared_function_infos().length());
18501cb0ef41Sopenharmony_ci  } else {
18511cb0ef41Sopenharmony_ci    // No overallocating shared_function_infos.
18521cb0ef41Sopenharmony_ci    CHECK_EQ(shared_function_info_count(), shared_function_infos().length());
18531cb0ef41Sopenharmony_ci  }
18541cb0ef41Sopenharmony_ci  for (int i = 0; i < shared_function_info_count(); ++i) {
18551cb0ef41Sopenharmony_ci    MaybeObject maybe_object = shared_function_infos().Get(i);
18561cb0ef41Sopenharmony_ci    HeapObject heap_object;
18571cb0ef41Sopenharmony_ci    CHECK(maybe_object->IsWeak() || maybe_object->IsCleared() ||
18581cb0ef41Sopenharmony_ci          (maybe_object->GetHeapObjectIfStrong(&heap_object) &&
18591cb0ef41Sopenharmony_ci           heap_object.IsUndefined(isolate)));
18601cb0ef41Sopenharmony_ci  }
18611cb0ef41Sopenharmony_ci}
18621cb0ef41Sopenharmony_ci
18631cb0ef41Sopenharmony_civoid NormalizedMapCache::NormalizedMapCacheVerify(Isolate* isolate) {
18641cb0ef41Sopenharmony_ci  WeakFixedArray::cast(*this).WeakFixedArrayVerify(isolate);
18651cb0ef41Sopenharmony_ci  if (FLAG_enable_slow_asserts) {
18661cb0ef41Sopenharmony_ci    for (int i = 0; i < length(); i++) {
18671cb0ef41Sopenharmony_ci      MaybeObject e = WeakFixedArray::Get(i);
18681cb0ef41Sopenharmony_ci      HeapObject heap_object;
18691cb0ef41Sopenharmony_ci      if (e->GetHeapObjectIfWeak(&heap_object)) {
18701cb0ef41Sopenharmony_ci        Map::cast(heap_object).DictionaryMapVerify(isolate);
18711cb0ef41Sopenharmony_ci      } else {
18721cb0ef41Sopenharmony_ci        CHECK(e->IsCleared() || (e->GetHeapObjectIfStrong(&heap_object) &&
18731cb0ef41Sopenharmony_ci                                 heap_object.IsUndefined(isolate)));
18741cb0ef41Sopenharmony_ci      }
18751cb0ef41Sopenharmony_ci    }
18761cb0ef41Sopenharmony_ci  }
18771cb0ef41Sopenharmony_ci}
18781cb0ef41Sopenharmony_ci
18791cb0ef41Sopenharmony_civoid PreparseData::PreparseDataVerify(Isolate* isolate) {
18801cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::PreparseDataVerify(*this, isolate);
18811cb0ef41Sopenharmony_ci  CHECK_LE(0, data_length());
18821cb0ef41Sopenharmony_ci  CHECK_LE(0, children_length());
18831cb0ef41Sopenharmony_ci
18841cb0ef41Sopenharmony_ci  for (int i = 0; i < children_length(); ++i) {
18851cb0ef41Sopenharmony_ci    Object child = get_child_raw(i);
18861cb0ef41Sopenharmony_ci    CHECK(child.IsNull() || child.IsPreparseData());
18871cb0ef41Sopenharmony_ci    VerifyPointer(isolate, child);
18881cb0ef41Sopenharmony_ci  }
18891cb0ef41Sopenharmony_ci}
18901cb0ef41Sopenharmony_ci
18911cb0ef41Sopenharmony_civoid CallSiteInfo::CallSiteInfoVerify(Isolate* isolate) {
18921cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::CallSiteInfoVerify(*this, isolate);
18931cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
18941cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsAsmJsWasm(), IsWasm());
18951cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsWasm(), receiver_or_instance().IsWasmInstanceObject());
18961cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsWasm(), function().IsSmi());
18971cb0ef41Sopenharmony_ci  CHECK_IMPLIES(!IsWasm(), function().IsJSFunction());
18981cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsAsync(), !IsWasm());
18991cb0ef41Sopenharmony_ci  CHECK_IMPLIES(IsConstructor(), !IsWasm());
19001cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
19011cb0ef41Sopenharmony_ci}
19021cb0ef41Sopenharmony_ci
19031cb0ef41Sopenharmony_civoid FunctionTemplateRareData::FunctionTemplateRareDataVerify(
19041cb0ef41Sopenharmony_ci    Isolate* isolate) {
19051cb0ef41Sopenharmony_ci  CHECK(c_function_overloads().IsFixedArray() ||
19061cb0ef41Sopenharmony_ci        c_function_overloads().IsUndefined(isolate));
19071cb0ef41Sopenharmony_ci}
19081cb0ef41Sopenharmony_ci
19091cb0ef41Sopenharmony_civoid StackFrameInfo::StackFrameInfoVerify(Isolate* isolate) {
19101cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::StackFrameInfoVerify(*this, isolate);
19111cb0ef41Sopenharmony_ci}
19121cb0ef41Sopenharmony_ci
19131cb0ef41Sopenharmony_civoid ErrorStackData::ErrorStackDataVerify(Isolate* isolate) {
19141cb0ef41Sopenharmony_ci  TorqueGeneratedClassVerifiers::ErrorStackDataVerify(*this, isolate);
19151cb0ef41Sopenharmony_ci  CHECK_IMPLIES(!call_site_infos_or_formatted_stack().IsFixedArray(),
19161cb0ef41Sopenharmony_ci                limit_or_stack_frame_infos().IsFixedArray());
19171cb0ef41Sopenharmony_ci}
19181cb0ef41Sopenharmony_ci
19191cb0ef41Sopenharmony_ci// Helper class for verifying the string table.
19201cb0ef41Sopenharmony_ciclass StringTableVerifier : public RootVisitor {
19211cb0ef41Sopenharmony_ci public:
19221cb0ef41Sopenharmony_ci  explicit StringTableVerifier(Isolate* isolate) : isolate_(isolate) {}
19231cb0ef41Sopenharmony_ci
19241cb0ef41Sopenharmony_ci  void VisitRootPointers(Root root, const char* description,
19251cb0ef41Sopenharmony_ci                         FullObjectSlot start, FullObjectSlot end) override {
19261cb0ef41Sopenharmony_ci    UNREACHABLE();
19271cb0ef41Sopenharmony_ci  }
19281cb0ef41Sopenharmony_ci  void VisitRootPointers(Root root, const char* description,
19291cb0ef41Sopenharmony_ci                         OffHeapObjectSlot start,
19301cb0ef41Sopenharmony_ci                         OffHeapObjectSlot end) override {
19311cb0ef41Sopenharmony_ci    // Visit all HeapObject pointers in [start, end).
19321cb0ef41Sopenharmony_ci    for (OffHeapObjectSlot p = start; p < end; ++p) {
19331cb0ef41Sopenharmony_ci      Object o = p.load(isolate_);
19341cb0ef41Sopenharmony_ci      DCHECK(!HasWeakHeapObjectTag(o));
19351cb0ef41Sopenharmony_ci      if (o.IsHeapObject()) {
19361cb0ef41Sopenharmony_ci        HeapObject object = HeapObject::cast(o);
19371cb0ef41Sopenharmony_ci        // Check that the string is actually internalized.
19381cb0ef41Sopenharmony_ci        CHECK(object.IsInternalizedString());
19391cb0ef41Sopenharmony_ci      }
19401cb0ef41Sopenharmony_ci    }
19411cb0ef41Sopenharmony_ci  }
19421cb0ef41Sopenharmony_ci
19431cb0ef41Sopenharmony_ci private:
19441cb0ef41Sopenharmony_ci  Isolate* isolate_;
19451cb0ef41Sopenharmony_ci};
19461cb0ef41Sopenharmony_ci
19471cb0ef41Sopenharmony_civoid StringTable::VerifyIfOwnedBy(Isolate* isolate) {
19481cb0ef41Sopenharmony_ci  DCHECK_EQ(isolate->string_table(), this);
19491cb0ef41Sopenharmony_ci  if (!isolate->OwnsStringTable()) return;
19501cb0ef41Sopenharmony_ci  StringTableVerifier verifier(isolate);
19511cb0ef41Sopenharmony_ci  IterateElements(&verifier);
19521cb0ef41Sopenharmony_ci}
19531cb0ef41Sopenharmony_ci
19541cb0ef41Sopenharmony_ci#endif  // VERIFY_HEAP
19551cb0ef41Sopenharmony_ci
19561cb0ef41Sopenharmony_ci#ifdef DEBUG
19571cb0ef41Sopenharmony_ci
19581cb0ef41Sopenharmony_civoid JSObject::IncrementSpillStatistics(Isolate* isolate,
19591cb0ef41Sopenharmony_ci                                        SpillInformation* info) {
19601cb0ef41Sopenharmony_ci  info->number_of_objects_++;
19611cb0ef41Sopenharmony_ci  // Named properties
19621cb0ef41Sopenharmony_ci  if (HasFastProperties()) {
19631cb0ef41Sopenharmony_ci    info->number_of_objects_with_fast_properties_++;
19641cb0ef41Sopenharmony_ci    info->number_of_fast_used_fields_ += map().NextFreePropertyIndex();
19651cb0ef41Sopenharmony_ci    info->number_of_fast_unused_fields_ += map().UnusedPropertyFields();
19661cb0ef41Sopenharmony_ci  } else if (IsJSGlobalObject()) {
19671cb0ef41Sopenharmony_ci    GlobalDictionary dict =
19681cb0ef41Sopenharmony_ci        JSGlobalObject::cast(*this).global_dictionary(kAcquireLoad);
19691cb0ef41Sopenharmony_ci    info->number_of_slow_used_properties_ += dict.NumberOfElements();
19701cb0ef41Sopenharmony_ci    info->number_of_slow_unused_properties_ +=
19711cb0ef41Sopenharmony_ci        dict.Capacity() - dict.NumberOfElements();
19721cb0ef41Sopenharmony_ci  } else if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) {
19731cb0ef41Sopenharmony_ci    SwissNameDictionary dict = property_dictionary_swiss();
19741cb0ef41Sopenharmony_ci    info->number_of_slow_used_properties_ += dict.NumberOfElements();
19751cb0ef41Sopenharmony_ci    info->number_of_slow_unused_properties_ +=
19761cb0ef41Sopenharmony_ci        dict.Capacity() - dict.NumberOfElements();
19771cb0ef41Sopenharmony_ci  } else {
19781cb0ef41Sopenharmony_ci    NameDictionary dict = property_dictionary();
19791cb0ef41Sopenharmony_ci    info->number_of_slow_used_properties_ += dict.NumberOfElements();
19801cb0ef41Sopenharmony_ci    info->number_of_slow_unused_properties_ +=
19811cb0ef41Sopenharmony_ci        dict.Capacity() - dict.NumberOfElements();
19821cb0ef41Sopenharmony_ci  }
19831cb0ef41Sopenharmony_ci  // Indexed properties
19841cb0ef41Sopenharmony_ci  switch (GetElementsKind()) {
19851cb0ef41Sopenharmony_ci    case HOLEY_SMI_ELEMENTS:
19861cb0ef41Sopenharmony_ci    case PACKED_SMI_ELEMENTS:
19871cb0ef41Sopenharmony_ci    case HOLEY_DOUBLE_ELEMENTS:
19881cb0ef41Sopenharmony_ci    case PACKED_DOUBLE_ELEMENTS:
19891cb0ef41Sopenharmony_ci    case HOLEY_ELEMENTS:
19901cb0ef41Sopenharmony_ci    case HOLEY_FROZEN_ELEMENTS:
19911cb0ef41Sopenharmony_ci    case HOLEY_SEALED_ELEMENTS:
19921cb0ef41Sopenharmony_ci    case HOLEY_NONEXTENSIBLE_ELEMENTS:
19931cb0ef41Sopenharmony_ci    case PACKED_ELEMENTS:
19941cb0ef41Sopenharmony_ci    case PACKED_FROZEN_ELEMENTS:
19951cb0ef41Sopenharmony_ci    case PACKED_SEALED_ELEMENTS:
19961cb0ef41Sopenharmony_ci    case PACKED_NONEXTENSIBLE_ELEMENTS:
19971cb0ef41Sopenharmony_ci    case FAST_STRING_WRAPPER_ELEMENTS: {
19981cb0ef41Sopenharmony_ci      info->number_of_objects_with_fast_elements_++;
19991cb0ef41Sopenharmony_ci      int holes = 0;
20001cb0ef41Sopenharmony_ci      FixedArray e = FixedArray::cast(elements());
20011cb0ef41Sopenharmony_ci      int len = e.length();
20021cb0ef41Sopenharmony_ci      for (int i = 0; i < len; i++) {
20031cb0ef41Sopenharmony_ci        if (e.get(i).IsTheHole(isolate)) holes++;
20041cb0ef41Sopenharmony_ci      }
20051cb0ef41Sopenharmony_ci      info->number_of_fast_used_elements_ += len - holes;
20061cb0ef41Sopenharmony_ci      info->number_of_fast_unused_elements_ += holes;
20071cb0ef41Sopenharmony_ci      break;
20081cb0ef41Sopenharmony_ci    }
20091cb0ef41Sopenharmony_ci
20101cb0ef41Sopenharmony_ci#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) case TYPE##_ELEMENTS:
20111cb0ef41Sopenharmony_ci
20121cb0ef41Sopenharmony_ci      TYPED_ARRAYS(TYPED_ARRAY_CASE)
20131cb0ef41Sopenharmony_ci      RAB_GSAB_TYPED_ARRAYS(TYPED_ARRAY_CASE)
20141cb0ef41Sopenharmony_ci#undef TYPED_ARRAY_CASE
20151cb0ef41Sopenharmony_ci      {
20161cb0ef41Sopenharmony_ci        info->number_of_objects_with_fast_elements_++;
20171cb0ef41Sopenharmony_ci        FixedArrayBase e = FixedArrayBase::cast(elements());
20181cb0ef41Sopenharmony_ci        info->number_of_fast_used_elements_ += e.length();
20191cb0ef41Sopenharmony_ci        break;
20201cb0ef41Sopenharmony_ci      }
20211cb0ef41Sopenharmony_ci    case DICTIONARY_ELEMENTS:
20221cb0ef41Sopenharmony_ci    case SLOW_STRING_WRAPPER_ELEMENTS: {
20231cb0ef41Sopenharmony_ci      NumberDictionary dict = element_dictionary();
20241cb0ef41Sopenharmony_ci      info->number_of_slow_used_elements_ += dict.NumberOfElements();
20251cb0ef41Sopenharmony_ci      info->number_of_slow_unused_elements_ +=
20261cb0ef41Sopenharmony_ci          dict.Capacity() - dict.NumberOfElements();
20271cb0ef41Sopenharmony_ci      break;
20281cb0ef41Sopenharmony_ci    }
20291cb0ef41Sopenharmony_ci    case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
20301cb0ef41Sopenharmony_ci    case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
20311cb0ef41Sopenharmony_ci    case WASM_ARRAY_ELEMENTS:
20321cb0ef41Sopenharmony_ci    case NO_ELEMENTS:
20331cb0ef41Sopenharmony_ci      break;
20341cb0ef41Sopenharmony_ci  }
20351cb0ef41Sopenharmony_ci}
20361cb0ef41Sopenharmony_ci
20371cb0ef41Sopenharmony_civoid JSObject::SpillInformation::Clear() {
20381cb0ef41Sopenharmony_ci  number_of_objects_ = 0;
20391cb0ef41Sopenharmony_ci  number_of_objects_with_fast_properties_ = 0;
20401cb0ef41Sopenharmony_ci  number_of_objects_with_fast_elements_ = 0;
20411cb0ef41Sopenharmony_ci  number_of_fast_used_fields_ = 0;
20421cb0ef41Sopenharmony_ci  number_of_fast_unused_fields_ = 0;
20431cb0ef41Sopenharmony_ci  number_of_slow_used_properties_ = 0;
20441cb0ef41Sopenharmony_ci  number_of_slow_unused_properties_ = 0;
20451cb0ef41Sopenharmony_ci  number_of_fast_used_elements_ = 0;
20461cb0ef41Sopenharmony_ci  number_of_fast_unused_elements_ = 0;
20471cb0ef41Sopenharmony_ci  number_of_slow_used_elements_ = 0;
20481cb0ef41Sopenharmony_ci  number_of_slow_unused_elements_ = 0;
20491cb0ef41Sopenharmony_ci}
20501cb0ef41Sopenharmony_ci
20511cb0ef41Sopenharmony_civoid JSObject::SpillInformation::Print() {
20521cb0ef41Sopenharmony_ci  PrintF("\n  JSObject Spill Statistics (#%d):\n", number_of_objects_);
20531cb0ef41Sopenharmony_ci
20541cb0ef41Sopenharmony_ci  PrintF("    - fast properties (#%d): %d (used) %d (unused)\n",
20551cb0ef41Sopenharmony_ci         number_of_objects_with_fast_properties_, number_of_fast_used_fields_,
20561cb0ef41Sopenharmony_ci         number_of_fast_unused_fields_);
20571cb0ef41Sopenharmony_ci
20581cb0ef41Sopenharmony_ci  PrintF("    - slow properties (#%d): %d (used) %d (unused)\n",
20591cb0ef41Sopenharmony_ci         number_of_objects_ - number_of_objects_with_fast_properties_,
20601cb0ef41Sopenharmony_ci         number_of_slow_used_properties_, number_of_slow_unused_properties_);
20611cb0ef41Sopenharmony_ci
20621cb0ef41Sopenharmony_ci  PrintF("    - fast elements (#%d): %d (used) %d (unused)\n",
20631cb0ef41Sopenharmony_ci         number_of_objects_with_fast_elements_, number_of_fast_used_elements_,
20641cb0ef41Sopenharmony_ci         number_of_fast_unused_elements_);
20651cb0ef41Sopenharmony_ci
20661cb0ef41Sopenharmony_ci  PrintF("    - slow elements (#%d): %d (used) %d (unused)\n",
20671cb0ef41Sopenharmony_ci         number_of_objects_ - number_of_objects_with_fast_elements_,
20681cb0ef41Sopenharmony_ci         number_of_slow_used_elements_, number_of_slow_unused_elements_);
20691cb0ef41Sopenharmony_ci
20701cb0ef41Sopenharmony_ci  PrintF("\n");
20711cb0ef41Sopenharmony_ci}
20721cb0ef41Sopenharmony_ci
20731cb0ef41Sopenharmony_cibool DescriptorArray::IsSortedNoDuplicates() {
20741cb0ef41Sopenharmony_ci  Name current_key;
20751cb0ef41Sopenharmony_ci  uint32_t current = 0;
20761cb0ef41Sopenharmony_ci  for (int i = 0; i < number_of_descriptors(); i++) {
20771cb0ef41Sopenharmony_ci    Name key = GetSortedKey(i);
20781cb0ef41Sopenharmony_ci    CHECK(key.HasHashCode());
20791cb0ef41Sopenharmony_ci    if (key == current_key) {
20801cb0ef41Sopenharmony_ci      Print();
20811cb0ef41Sopenharmony_ci      return false;
20821cb0ef41Sopenharmony_ci    }
20831cb0ef41Sopenharmony_ci    current_key = key;
20841cb0ef41Sopenharmony_ci    uint32_t hash = key.hash();
20851cb0ef41Sopenharmony_ci    if (hash < current) {
20861cb0ef41Sopenharmony_ci      Print();
20871cb0ef41Sopenharmony_ci      return false;
20881cb0ef41Sopenharmony_ci    }
20891cb0ef41Sopenharmony_ci    current = hash;
20901cb0ef41Sopenharmony_ci  }
20911cb0ef41Sopenharmony_ci  return true;
20921cb0ef41Sopenharmony_ci}
20931cb0ef41Sopenharmony_ci
20941cb0ef41Sopenharmony_cibool TransitionArray::IsSortedNoDuplicates() {
20951cb0ef41Sopenharmony_ci  Name prev_key;
20961cb0ef41Sopenharmony_ci  PropertyKind prev_kind = PropertyKind::kData;
20971cb0ef41Sopenharmony_ci  PropertyAttributes prev_attributes = NONE;
20981cb0ef41Sopenharmony_ci  uint32_t prev_hash = 0;
20991cb0ef41Sopenharmony_ci
21001cb0ef41Sopenharmony_ci  for (int i = 0; i < number_of_transitions(); i++) {
21011cb0ef41Sopenharmony_ci    Name key = GetSortedKey(i);
21021cb0ef41Sopenharmony_ci    CHECK(key.HasHashCode());
21031cb0ef41Sopenharmony_ci    uint32_t hash = key.hash();
21041cb0ef41Sopenharmony_ci    PropertyKind kind = PropertyKind::kData;
21051cb0ef41Sopenharmony_ci    PropertyAttributes attributes = NONE;
21061cb0ef41Sopenharmony_ci    if (!TransitionsAccessor::IsSpecialTransition(key.GetReadOnlyRoots(),
21071cb0ef41Sopenharmony_ci                                                  key)) {
21081cb0ef41Sopenharmony_ci      Map target = GetTarget(i);
21091cb0ef41Sopenharmony_ci      PropertyDetails details =
21101cb0ef41Sopenharmony_ci          TransitionsAccessor::GetTargetDetails(key, target);
21111cb0ef41Sopenharmony_ci      kind = details.kind();
21121cb0ef41Sopenharmony_ci      attributes = details.attributes();
21131cb0ef41Sopenharmony_ci    } else {
21141cb0ef41Sopenharmony_ci      // Duplicate entries are not allowed for non-property transitions.
21151cb0ef41Sopenharmony_ci      DCHECK_NE(prev_key, key);
21161cb0ef41Sopenharmony_ci    }
21171cb0ef41Sopenharmony_ci
21181cb0ef41Sopenharmony_ci    int cmp = CompareKeys(prev_key, prev_hash, prev_kind, prev_attributes, key,
21191cb0ef41Sopenharmony_ci                          hash, kind, attributes);
21201cb0ef41Sopenharmony_ci    if (cmp >= 0) {
21211cb0ef41Sopenharmony_ci      Print();
21221cb0ef41Sopenharmony_ci      return false;
21231cb0ef41Sopenharmony_ci    }
21241cb0ef41Sopenharmony_ci    prev_key = key;
21251cb0ef41Sopenharmony_ci    prev_hash = hash;
21261cb0ef41Sopenharmony_ci    prev_attributes = attributes;
21271cb0ef41Sopenharmony_ci    prev_kind = kind;
21281cb0ef41Sopenharmony_ci  }
21291cb0ef41Sopenharmony_ci  return true;
21301cb0ef41Sopenharmony_ci}
21311cb0ef41Sopenharmony_ci
21321cb0ef41Sopenharmony_cibool TransitionsAccessor::IsSortedNoDuplicates() {
21331cb0ef41Sopenharmony_ci  // Simple and non-existent transitions are always sorted.
21341cb0ef41Sopenharmony_ci  if (encoding() != kFullTransitionArray) return true;
21351cb0ef41Sopenharmony_ci  return transitions().IsSortedNoDuplicates();
21361cb0ef41Sopenharmony_ci}
21371cb0ef41Sopenharmony_ci
21381cb0ef41Sopenharmony_cistatic bool CheckOneBackPointer(Map current_map, Object target) {
21391cb0ef41Sopenharmony_ci  return !target.IsMap() || Map::cast(target).GetBackPointer() == current_map;
21401cb0ef41Sopenharmony_ci}
21411cb0ef41Sopenharmony_ci
21421cb0ef41Sopenharmony_cibool TransitionsAccessor::IsConsistentWithBackPointers() {
21431cb0ef41Sopenharmony_ci  int num_transitions = NumberOfTransitions();
21441cb0ef41Sopenharmony_ci  for (int i = 0; i < num_transitions; i++) {
21451cb0ef41Sopenharmony_ci    Map target = GetTarget(i);
21461cb0ef41Sopenharmony_ci    if (!CheckOneBackPointer(map_, target)) return false;
21471cb0ef41Sopenharmony_ci  }
21481cb0ef41Sopenharmony_ci  return true;
21491cb0ef41Sopenharmony_ci}
21501cb0ef41Sopenharmony_ci
21511cb0ef41Sopenharmony_ci#undef USE_TORQUE_VERIFIER
21521cb0ef41Sopenharmony_ci
21531cb0ef41Sopenharmony_ci#endif  // DEBUG
21541cb0ef41Sopenharmony_ci
21551cb0ef41Sopenharmony_ci}  // namespace internal
21561cb0ef41Sopenharmony_ci}  // namespace v8
2157