11cb0ef41Sopenharmony_ci// Copyright 2021 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/baseline/bytecode-offset-iterator.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/objects/code-inl.h" 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cinamespace v8 { 101cb0ef41Sopenharmony_cinamespace internal { 111cb0ef41Sopenharmony_cinamespace baseline { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciBytecodeOffsetIterator::BytecodeOffsetIterator(Handle<ByteArray> mapping_table, 141cb0ef41Sopenharmony_ci Handle<BytecodeArray> bytecodes) 151cb0ef41Sopenharmony_ci : mapping_table_(mapping_table), 161cb0ef41Sopenharmony_ci data_start_address_(mapping_table_->GetDataStartAddress()), 171cb0ef41Sopenharmony_ci data_length_(mapping_table_->length()), 181cb0ef41Sopenharmony_ci current_index_(0), 191cb0ef41Sopenharmony_ci bytecode_iterator_(bytecodes), 201cb0ef41Sopenharmony_ci local_heap_(LocalHeap::Current() 211cb0ef41Sopenharmony_ci ? LocalHeap::Current() 221cb0ef41Sopenharmony_ci : Isolate::Current()->main_thread_local_heap()) { 231cb0ef41Sopenharmony_ci local_heap_->AddGCEpilogueCallback(UpdatePointersCallback, this); 241cb0ef41Sopenharmony_ci Initialize(); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciBytecodeOffsetIterator::BytecodeOffsetIterator(ByteArray mapping_table, 281cb0ef41Sopenharmony_ci BytecodeArray bytecodes) 291cb0ef41Sopenharmony_ci : data_start_address_(mapping_table.GetDataStartAddress()), 301cb0ef41Sopenharmony_ci data_length_(mapping_table.length()), 311cb0ef41Sopenharmony_ci current_index_(0), 321cb0ef41Sopenharmony_ci bytecode_handle_storage_(bytecodes), 331cb0ef41Sopenharmony_ci // In the non-handlified version, no GC is allowed. We use a "dummy" 341cb0ef41Sopenharmony_ci // handle to pass the BytecodeArray to the BytecodeArrayIterator, which 351cb0ef41Sopenharmony_ci // is fine since no objects will be moved. 361cb0ef41Sopenharmony_ci bytecode_iterator_(Handle<BytecodeArray>( 371cb0ef41Sopenharmony_ci reinterpret_cast<Address*>(&bytecode_handle_storage_))), 381cb0ef41Sopenharmony_ci local_heap_(nullptr) { 391cb0ef41Sopenharmony_ci no_gc_.emplace(); 401cb0ef41Sopenharmony_ci Initialize(); 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciBytecodeOffsetIterator::~BytecodeOffsetIterator() { 441cb0ef41Sopenharmony_ci if (local_heap_ != nullptr) { 451cb0ef41Sopenharmony_ci local_heap_->RemoveGCEpilogueCallback(UpdatePointersCallback, this); 461cb0ef41Sopenharmony_ci } 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_civoid BytecodeOffsetIterator::Initialize() { 501cb0ef41Sopenharmony_ci // Initialize values for the prologue. 511cb0ef41Sopenharmony_ci // The first recorded position is at the start of the first bytecode. 521cb0ef41Sopenharmony_ci current_pc_start_offset_ = 0; 531cb0ef41Sopenharmony_ci current_pc_end_offset_ = ReadPosition(); 541cb0ef41Sopenharmony_ci current_bytecode_offset_ = kFunctionEntryBytecodeOffset; 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_civoid BytecodeOffsetIterator::UpdatePointers() { 581cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 591cb0ef41Sopenharmony_ci DCHECK(!mapping_table_.is_null()); 601cb0ef41Sopenharmony_ci data_start_address_ = mapping_table_->GetDataStartAddress(); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci} // namespace baseline 641cb0ef41Sopenharmony_ci} // namespace internal 651cb0ef41Sopenharmony_ci} // namespace v8 66