11cb0ef41Sopenharmony_ci// Copyright 2019 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/objects/osr-optimized-code-cache.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/execution/isolate-inl.h"
81cb0ef41Sopenharmony_ci#include "src/objects/code.h"
91cb0ef41Sopenharmony_ci#include "src/objects/maybe-object.h"
101cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// static
161cb0ef41Sopenharmony_ciHandle<OSROptimizedCodeCache> OSROptimizedCodeCache::Empty(Isolate* isolate) {
171cb0ef41Sopenharmony_ci  return Handle<OSROptimizedCodeCache>::cast(
181cb0ef41Sopenharmony_ci      isolate->factory()->empty_weak_fixed_array());
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// static
221cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::Insert(Isolate* isolate,
231cb0ef41Sopenharmony_ci                                   Handle<NativeContext> native_context,
241cb0ef41Sopenharmony_ci                                   Handle<SharedFunctionInfo> shared,
251cb0ef41Sopenharmony_ci                                   Handle<CodeT> code,
261cb0ef41Sopenharmony_ci                                   BytecodeOffset osr_offset) {
271cb0ef41Sopenharmony_ci  DCHECK(!osr_offset.IsNone());
281cb0ef41Sopenharmony_ci  DCHECK(!isolate->serializer_enabled());
291cb0ef41Sopenharmony_ci  DCHECK(CodeKindIsOptimizedJSFunction(code->kind()));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(),
321cb0ef41Sopenharmony_ci                                          isolate);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  if (shared->osr_code_cache_state() == kNotCached) {
351cb0ef41Sopenharmony_ci    DCHECK_EQ(osr_cache->FindEntry(*shared, osr_offset), -1);
361cb0ef41Sopenharmony_ci  } else if (osr_cache->FindEntry(*shared, osr_offset) != -1) {
371cb0ef41Sopenharmony_ci    return;  // Already cached for a different JSFunction.
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  STATIC_ASSERT(kEntryLength == 3);
411cb0ef41Sopenharmony_ci  int entry = -1;
421cb0ef41Sopenharmony_ci  for (int index = 0; index < osr_cache->length(); index += kEntryLength) {
431cb0ef41Sopenharmony_ci    if (osr_cache->Get(index + kSharedOffset)->IsCleared() ||
441cb0ef41Sopenharmony_ci        osr_cache->Get(index + kCachedCodeOffset)->IsCleared()) {
451cb0ef41Sopenharmony_ci      entry = index;
461cb0ef41Sopenharmony_ci      break;
471cb0ef41Sopenharmony_ci    }
481cb0ef41Sopenharmony_ci  }
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  if (entry == -1) {
511cb0ef41Sopenharmony_ci    if (osr_cache->length() + kEntryLength <= kMaxLength) {
521cb0ef41Sopenharmony_ci      entry = GrowOSRCache(isolate, native_context, &osr_cache);
531cb0ef41Sopenharmony_ci    } else {
541cb0ef41Sopenharmony_ci      // We reached max capacity and cannot grow further. Reuse an existing
551cb0ef41Sopenharmony_ci      // entry.
561cb0ef41Sopenharmony_ci      // TODO(mythria): We could use better mechanisms (like lru) to replace
571cb0ef41Sopenharmony_ci      // existing entries. Though we don't expect this to be a common case, so
581cb0ef41Sopenharmony_ci      // for now choosing to replace the first entry.
591cb0ef41Sopenharmony_ci      osr_cache->ClearEntry(0, isolate);
601cb0ef41Sopenharmony_ci      entry = 0;
611cb0ef41Sopenharmony_ci    }
621cb0ef41Sopenharmony_ci  }
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci  osr_cache->InitializeEntry(entry, *shared, *code, osr_offset);
651cb0ef41Sopenharmony_ci}
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::Clear(Isolate* isolate,
681cb0ef41Sopenharmony_ci                                  NativeContext native_context) {
691cb0ef41Sopenharmony_ci  native_context.set_osr_code_cache(*OSROptimizedCodeCache::Empty(isolate));
701cb0ef41Sopenharmony_ci}
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::Compact(Isolate* isolate,
731cb0ef41Sopenharmony_ci                                    Handle<NativeContext> native_context) {
741cb0ef41Sopenharmony_ci  Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(),
751cb0ef41Sopenharmony_ci                                          isolate);
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  // Re-adjust the cache so all the valid entries are on one side. This will
781cb0ef41Sopenharmony_ci  // enable us to compress the cache if needed.
791cb0ef41Sopenharmony_ci  int curr_valid_index = 0;
801cb0ef41Sopenharmony_ci  for (int curr_index = 0; curr_index < osr_cache->length();
811cb0ef41Sopenharmony_ci       curr_index += kEntryLength) {
821cb0ef41Sopenharmony_ci    if (osr_cache->Get(curr_index + kSharedOffset)->IsCleared() ||
831cb0ef41Sopenharmony_ci        osr_cache->Get(curr_index + kCachedCodeOffset)->IsCleared()) {
841cb0ef41Sopenharmony_ci      continue;
851cb0ef41Sopenharmony_ci    }
861cb0ef41Sopenharmony_ci    if (curr_valid_index != curr_index) {
871cb0ef41Sopenharmony_ci      osr_cache->MoveEntry(curr_index, curr_valid_index, isolate);
881cb0ef41Sopenharmony_ci    }
891cb0ef41Sopenharmony_ci    curr_valid_index += kEntryLength;
901cb0ef41Sopenharmony_ci  }
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  if (!NeedsTrimming(curr_valid_index, osr_cache->length())) return;
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci  Handle<OSROptimizedCodeCache> new_osr_cache =
951cb0ef41Sopenharmony_ci      Handle<OSROptimizedCodeCache>::cast(isolate->factory()->NewWeakFixedArray(
961cb0ef41Sopenharmony_ci          CapacityForLength(curr_valid_index), AllocationType::kOld));
971cb0ef41Sopenharmony_ci  DCHECK_LT(new_osr_cache->length(), osr_cache->length());
981cb0ef41Sopenharmony_ci  {
991cb0ef41Sopenharmony_ci    DisallowGarbageCollection no_gc;
1001cb0ef41Sopenharmony_ci    new_osr_cache->CopyElements(isolate, 0, *osr_cache, 0,
1011cb0ef41Sopenharmony_ci                                new_osr_cache->length(),
1021cb0ef41Sopenharmony_ci                                new_osr_cache->GetWriteBarrierMode(no_gc));
1031cb0ef41Sopenharmony_ci  }
1041cb0ef41Sopenharmony_ci  native_context->set_osr_code_cache(*new_osr_cache);
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ciCodeT OSROptimizedCodeCache::TryGet(SharedFunctionInfo shared,
1081cb0ef41Sopenharmony_ci                                    BytecodeOffset osr_offset,
1091cb0ef41Sopenharmony_ci                                    Isolate* isolate) {
1101cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
1111cb0ef41Sopenharmony_ci  int index = FindEntry(shared, osr_offset);
1121cb0ef41Sopenharmony_ci  if (index == -1) return {};
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ci  CodeT code = GetCodeFromEntry(index);
1151cb0ef41Sopenharmony_ci  if (code.is_null()) {
1161cb0ef41Sopenharmony_ci    ClearEntry(index, isolate);
1171cb0ef41Sopenharmony_ci    return {};
1181cb0ef41Sopenharmony_ci  }
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci  DCHECK(code.is_optimized_code() && !code.marked_for_deoptimization());
1211cb0ef41Sopenharmony_ci  return code;
1221cb0ef41Sopenharmony_ci}
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::EvictDeoptimizedCode(Isolate* isolate) {
1251cb0ef41Sopenharmony_ci  // This is called from DeoptimizeMarkedCodeForContext that uses raw pointers
1261cb0ef41Sopenharmony_ci  // and hence the DisallowGarbageCollection scope here.
1271cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
1281cb0ef41Sopenharmony_ci  for (int index = 0; index < length(); index += kEntryLength) {
1291cb0ef41Sopenharmony_ci    MaybeObject code_entry = Get(index + kCachedCodeOffset);
1301cb0ef41Sopenharmony_ci    HeapObject heap_object;
1311cb0ef41Sopenharmony_ci    if (!code_entry->GetHeapObject(&heap_object)) continue;
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci    CodeT code = CodeT::cast(heap_object);
1341cb0ef41Sopenharmony_ci    DCHECK(code.is_optimized_code());
1351cb0ef41Sopenharmony_ci    if (!code.marked_for_deoptimization()) continue;
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci    ClearEntry(index, isolate);
1381cb0ef41Sopenharmony_ci  }
1391cb0ef41Sopenharmony_ci}
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_cistd::vector<BytecodeOffset> OSROptimizedCodeCache::OsrOffsetsFor(
1421cb0ef41Sopenharmony_ci    SharedFunctionInfo shared) {
1431cb0ef41Sopenharmony_ci  DisallowGarbageCollection gc;
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci  const OSRCodeCacheStateOfSFI state = shared.osr_code_cache_state();
1461cb0ef41Sopenharmony_ci  if (state == kNotCached) return {};
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci  std::vector<BytecodeOffset> offsets;
1491cb0ef41Sopenharmony_ci  for (int index = 0; index < length(); index += kEntryLength) {
1501cb0ef41Sopenharmony_ci    if (GetSFIFromEntry(index) != shared) continue;
1511cb0ef41Sopenharmony_ci    offsets.emplace_back(GetBytecodeOffsetFromEntry(index));
1521cb0ef41Sopenharmony_ci    if (state == kCachedOnce) return offsets;
1531cb0ef41Sopenharmony_ci  }
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  return offsets;
1561cb0ef41Sopenharmony_ci}
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_cibase::Optional<BytecodeOffset> OSROptimizedCodeCache::FirstOsrOffsetFor(
1591cb0ef41Sopenharmony_ci    SharedFunctionInfo shared) {
1601cb0ef41Sopenharmony_ci  DisallowGarbageCollection gc;
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  const OSRCodeCacheStateOfSFI state = shared.osr_code_cache_state();
1631cb0ef41Sopenharmony_ci  if (state == kNotCached) return {};
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  for (int index = 0; index < length(); index += kEntryLength) {
1661cb0ef41Sopenharmony_ci    if (GetSFIFromEntry(index) != shared) continue;
1671cb0ef41Sopenharmony_ci    return GetBytecodeOffsetFromEntry(index);
1681cb0ef41Sopenharmony_ci  }
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci  return {};
1711cb0ef41Sopenharmony_ci}
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ciint OSROptimizedCodeCache::GrowOSRCache(
1741cb0ef41Sopenharmony_ci    Isolate* isolate, Handle<NativeContext> native_context,
1751cb0ef41Sopenharmony_ci    Handle<OSROptimizedCodeCache>* osr_cache) {
1761cb0ef41Sopenharmony_ci  int old_length = (*osr_cache)->length();
1771cb0ef41Sopenharmony_ci  int grow_by = CapacityForLength(old_length) - old_length;
1781cb0ef41Sopenharmony_ci  DCHECK_GT(grow_by, kEntryLength);
1791cb0ef41Sopenharmony_ci  *osr_cache = Handle<OSROptimizedCodeCache>::cast(
1801cb0ef41Sopenharmony_ci      isolate->factory()->CopyWeakFixedArrayAndGrow(*osr_cache, grow_by));
1811cb0ef41Sopenharmony_ci  for (int i = old_length; i < (*osr_cache)->length(); i++) {
1821cb0ef41Sopenharmony_ci    (*osr_cache)->Set(i, HeapObjectReference::ClearedValue(isolate));
1831cb0ef41Sopenharmony_ci  }
1841cb0ef41Sopenharmony_ci  native_context->set_osr_code_cache(**osr_cache);
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci  return old_length;
1871cb0ef41Sopenharmony_ci}
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ciCodeT OSROptimizedCodeCache::GetCodeFromEntry(int index) {
1901cb0ef41Sopenharmony_ci  DCHECK_LE(index + OSRCodeCacheConstants::kEntryLength, length());
1911cb0ef41Sopenharmony_ci  DCHECK_EQ(index % kEntryLength, 0);
1921cb0ef41Sopenharmony_ci  HeapObject code_entry;
1931cb0ef41Sopenharmony_ci  Get(index + OSRCodeCacheConstants::kCachedCodeOffset)
1941cb0ef41Sopenharmony_ci      ->GetHeapObject(&code_entry);
1951cb0ef41Sopenharmony_ci  if (code_entry.is_null()) return CodeT();
1961cb0ef41Sopenharmony_ci  return CodeT::cast(code_entry);
1971cb0ef41Sopenharmony_ci}
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ciSharedFunctionInfo OSROptimizedCodeCache::GetSFIFromEntry(int index) {
2001cb0ef41Sopenharmony_ci  DCHECK_LE(index + OSRCodeCacheConstants::kEntryLength, length());
2011cb0ef41Sopenharmony_ci  DCHECK_EQ(index % kEntryLength, 0);
2021cb0ef41Sopenharmony_ci  HeapObject sfi_entry;
2031cb0ef41Sopenharmony_ci  Get(index + OSRCodeCacheConstants::kSharedOffset)->GetHeapObject(&sfi_entry);
2041cb0ef41Sopenharmony_ci  return sfi_entry.is_null() ? SharedFunctionInfo()
2051cb0ef41Sopenharmony_ci                             : SharedFunctionInfo::cast(sfi_entry);
2061cb0ef41Sopenharmony_ci}
2071cb0ef41Sopenharmony_ci
2081cb0ef41Sopenharmony_ciBytecodeOffset OSROptimizedCodeCache::GetBytecodeOffsetFromEntry(int index) {
2091cb0ef41Sopenharmony_ci  DCHECK_LE(index + OSRCodeCacheConstants::kEntryLength, length());
2101cb0ef41Sopenharmony_ci  DCHECK_EQ(index % kEntryLength, 0);
2111cb0ef41Sopenharmony_ci  Smi osr_offset_entry;
2121cb0ef41Sopenharmony_ci  Get(index + kOsrIdOffset)->ToSmi(&osr_offset_entry);
2131cb0ef41Sopenharmony_ci  return BytecodeOffset(osr_offset_entry.value());
2141cb0ef41Sopenharmony_ci}
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ciint OSROptimizedCodeCache::FindEntry(SharedFunctionInfo shared,
2171cb0ef41Sopenharmony_ci                                     BytecodeOffset osr_offset) {
2181cb0ef41Sopenharmony_ci  DisallowGarbageCollection no_gc;
2191cb0ef41Sopenharmony_ci  DCHECK(!osr_offset.IsNone());
2201cb0ef41Sopenharmony_ci  for (int index = 0; index < length(); index += kEntryLength) {
2211cb0ef41Sopenharmony_ci    if (GetSFIFromEntry(index) != shared) continue;
2221cb0ef41Sopenharmony_ci    if (GetBytecodeOffsetFromEntry(index) != osr_offset) continue;
2231cb0ef41Sopenharmony_ci    return index;
2241cb0ef41Sopenharmony_ci  }
2251cb0ef41Sopenharmony_ci  return -1;
2261cb0ef41Sopenharmony_ci}
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::ClearEntry(int index, Isolate* isolate) {
2291cb0ef41Sopenharmony_ci  SharedFunctionInfo shared = GetSFIFromEntry(index);
2301cb0ef41Sopenharmony_ci  DCHECK_GT(shared.osr_code_cache_state(), kNotCached);
2311cb0ef41Sopenharmony_ci  if (V8_LIKELY(shared.osr_code_cache_state() == kCachedOnce)) {
2321cb0ef41Sopenharmony_ci    shared.set_osr_code_cache_state(kNotCached);
2331cb0ef41Sopenharmony_ci  } else if (shared.osr_code_cache_state() == kCachedMultiple) {
2341cb0ef41Sopenharmony_ci    int osr_code_cache_count = 0;
2351cb0ef41Sopenharmony_ci    for (int index = 0; index < length(); index += kEntryLength) {
2361cb0ef41Sopenharmony_ci      if (GetSFIFromEntry(index) == shared) {
2371cb0ef41Sopenharmony_ci        osr_code_cache_count++;
2381cb0ef41Sopenharmony_ci      }
2391cb0ef41Sopenharmony_ci    }
2401cb0ef41Sopenharmony_ci    if (osr_code_cache_count == 2) {
2411cb0ef41Sopenharmony_ci      shared.set_osr_code_cache_state(kCachedOnce);
2421cb0ef41Sopenharmony_ci    }
2431cb0ef41Sopenharmony_ci  }
2441cb0ef41Sopenharmony_ci  HeapObjectReference cleared_value =
2451cb0ef41Sopenharmony_ci      HeapObjectReference::ClearedValue(isolate);
2461cb0ef41Sopenharmony_ci  Set(index + OSRCodeCacheConstants::kSharedOffset, cleared_value);
2471cb0ef41Sopenharmony_ci  Set(index + OSRCodeCacheConstants::kCachedCodeOffset, cleared_value);
2481cb0ef41Sopenharmony_ci  Set(index + OSRCodeCacheConstants::kOsrIdOffset, cleared_value);
2491cb0ef41Sopenharmony_ci}
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::InitializeEntry(int entry,
2521cb0ef41Sopenharmony_ci                                            SharedFunctionInfo shared,
2531cb0ef41Sopenharmony_ci                                            CodeT code,
2541cb0ef41Sopenharmony_ci                                            BytecodeOffset osr_offset) {
2551cb0ef41Sopenharmony_ci  Set(entry + OSRCodeCacheConstants::kSharedOffset,
2561cb0ef41Sopenharmony_ci      HeapObjectReference::Weak(shared));
2571cb0ef41Sopenharmony_ci  HeapObjectReference weak_code_entry = HeapObjectReference::Weak(code);
2581cb0ef41Sopenharmony_ci  Set(entry + OSRCodeCacheConstants::kCachedCodeOffset, weak_code_entry);
2591cb0ef41Sopenharmony_ci  Set(entry + OSRCodeCacheConstants::kOsrIdOffset,
2601cb0ef41Sopenharmony_ci      MaybeObject::FromSmi(Smi::FromInt(osr_offset.ToInt())));
2611cb0ef41Sopenharmony_ci  if (V8_LIKELY(shared.osr_code_cache_state() == kNotCached)) {
2621cb0ef41Sopenharmony_ci    shared.set_osr_code_cache_state(kCachedOnce);
2631cb0ef41Sopenharmony_ci  } else if (shared.osr_code_cache_state() == kCachedOnce) {
2641cb0ef41Sopenharmony_ci    shared.set_osr_code_cache_state(kCachedMultiple);
2651cb0ef41Sopenharmony_ci  }
2661cb0ef41Sopenharmony_ci}
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::MoveEntry(int src, int dst, Isolate* isolate) {
2691cb0ef41Sopenharmony_ci  Set(dst + OSRCodeCacheConstants::kSharedOffset,
2701cb0ef41Sopenharmony_ci      Get(src + OSRCodeCacheConstants::kSharedOffset));
2711cb0ef41Sopenharmony_ci  Set(dst + OSRCodeCacheConstants::kCachedCodeOffset,
2721cb0ef41Sopenharmony_ci      Get(src + OSRCodeCacheConstants::kCachedCodeOffset));
2731cb0ef41Sopenharmony_ci  Set(dst + OSRCodeCacheConstants::kOsrIdOffset, Get(src + kOsrIdOffset));
2741cb0ef41Sopenharmony_ci  HeapObjectReference cleared_value =
2751cb0ef41Sopenharmony_ci      HeapObjectReference::ClearedValue(isolate);
2761cb0ef41Sopenharmony_ci  Set(src + OSRCodeCacheConstants::kSharedOffset, cleared_value);
2771cb0ef41Sopenharmony_ci  Set(src + OSRCodeCacheConstants::kCachedCodeOffset, cleared_value);
2781cb0ef41Sopenharmony_ci  Set(src + OSRCodeCacheConstants::kOsrIdOffset, cleared_value);
2791cb0ef41Sopenharmony_ci}
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciint OSROptimizedCodeCache::CapacityForLength(int curr_length) {
2821cb0ef41Sopenharmony_ci  // TODO(mythria): This is a randomly chosen heuristic and is not based on any
2831cb0ef41Sopenharmony_ci  // data. We may have to tune this later.
2841cb0ef41Sopenharmony_ci  if (curr_length == 0) return kInitialLength;
2851cb0ef41Sopenharmony_ci  if (curr_length * 2 > kMaxLength) return kMaxLength;
2861cb0ef41Sopenharmony_ci  return curr_length * 2;
2871cb0ef41Sopenharmony_ci}
2881cb0ef41Sopenharmony_ci
2891cb0ef41Sopenharmony_cibool OSROptimizedCodeCache::NeedsTrimming(int num_valid_entries,
2901cb0ef41Sopenharmony_ci                                          int curr_length) {
2911cb0ef41Sopenharmony_ci  return curr_length > kInitialLength && curr_length > num_valid_entries * 3;
2921cb0ef41Sopenharmony_ci}
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ciMaybeObject OSROptimizedCodeCache::RawGetForTesting(int index) const {
2951cb0ef41Sopenharmony_ci  return WeakFixedArray::Get(index);
2961cb0ef41Sopenharmony_ci}
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_civoid OSROptimizedCodeCache::RawSetForTesting(int index, MaybeObject value) {
2991cb0ef41Sopenharmony_ci  WeakFixedArray::Set(index, value);
3001cb0ef41Sopenharmony_ci}
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci}  // namespace internal
3031cb0ef41Sopenharmony_ci}  // namespace v8
304