1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2024 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #include "common_transaction_test.h" 18*795d594fSAndroid Build Coastguard Worker 19*795d594fSAndroid Build Coastguard Worker #include "aot_class_linker.h" 20*795d594fSAndroid Build Coastguard Worker #include "runtime.h" 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 23*795d594fSAndroid Build Coastguard Worker 24*795d594fSAndroid Build Coastguard Worker class CommonTransactionTestCompilerCallbacks : public CompilerCallbacks { 25*795d594fSAndroid Build Coastguard Worker public: CommonTransactionTestCompilerCallbacks()26*795d594fSAndroid Build Coastguard Worker CommonTransactionTestCompilerCallbacks() 27*795d594fSAndroid Build Coastguard Worker : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp) {} 28*795d594fSAndroid Build Coastguard Worker CreateAotClassLinker(InternTable * intern_table)29*795d594fSAndroid Build Coastguard Worker ClassLinker* CreateAotClassLinker(InternTable* intern_table) override { 30*795d594fSAndroid Build Coastguard Worker return new AotClassLinker(intern_table); 31*795d594fSAndroid Build Coastguard Worker } 32*795d594fSAndroid Build Coastguard Worker AddUncompilableMethod(MethodReference ref)33*795d594fSAndroid Build Coastguard Worker void AddUncompilableMethod([[maybe_unused]] MethodReference ref) override {} AddUncompilableClass(ClassReference ref)34*795d594fSAndroid Build Coastguard Worker void AddUncompilableClass([[maybe_unused]] ClassReference ref) override {} ClassRejected(ClassReference ref)35*795d594fSAndroid Build Coastguard Worker void ClassRejected([[maybe_unused]] ClassReference ref) override {} 36*795d594fSAndroid Build Coastguard Worker GetVerifierDeps() const37*795d594fSAndroid Build Coastguard Worker verifier::VerifierDeps* GetVerifierDeps() const override { return nullptr; } 38*795d594fSAndroid Build Coastguard Worker 39*795d594fSAndroid Build Coastguard Worker private: 40*795d594fSAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(CommonTransactionTestCompilerCallbacks); 41*795d594fSAndroid Build Coastguard Worker }; 42*795d594fSAndroid Build Coastguard Worker CreateCompilerCallbacks()43*795d594fSAndroid Build Coastguard WorkerCompilerCallbacks* CommonTransactionTestImpl::CreateCompilerCallbacks() { 44*795d594fSAndroid Build Coastguard Worker return new CommonTransactionTestCompilerCallbacks(); 45*795d594fSAndroid Build Coastguard Worker } 46*795d594fSAndroid Build Coastguard Worker EnterTransactionMode()47*795d594fSAndroid Build Coastguard Workervoid CommonTransactionTestImpl::EnterTransactionMode() { 48*795d594fSAndroid Build Coastguard Worker CHECK(!Runtime::Current()->IsActiveTransaction()); 49*795d594fSAndroid Build Coastguard Worker AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 50*795d594fSAndroid Build Coastguard Worker class_linker->EnterTransactionMode(/*strict=*/ false, /*root=*/ nullptr); 51*795d594fSAndroid Build Coastguard Worker } 52*795d594fSAndroid Build Coastguard Worker ExitTransactionMode()53*795d594fSAndroid Build Coastguard Workervoid CommonTransactionTestImpl::ExitTransactionMode() { 54*795d594fSAndroid Build Coastguard Worker AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 55*795d594fSAndroid Build Coastguard Worker class_linker->ExitTransactionMode(); 56*795d594fSAndroid Build Coastguard Worker CHECK(!Runtime::Current()->IsActiveTransaction()); 57*795d594fSAndroid Build Coastguard Worker } 58*795d594fSAndroid Build Coastguard Worker RollbackAndExitTransactionMode()59*795d594fSAndroid Build Coastguard Workervoid CommonTransactionTestImpl::RollbackAndExitTransactionMode() { 60*795d594fSAndroid Build Coastguard Worker AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 61*795d594fSAndroid Build Coastguard Worker class_linker->RollbackAndExitTransactionMode(); 62*795d594fSAndroid Build Coastguard Worker CHECK(!Runtime::Current()->IsActiveTransaction()); 63*795d594fSAndroid Build Coastguard Worker } 64*795d594fSAndroid Build Coastguard Worker IsTransactionAborted()65*795d594fSAndroid Build Coastguard Workerbool CommonTransactionTestImpl::IsTransactionAborted() { 66*795d594fSAndroid Build Coastguard Worker if (!Runtime::Current()->IsActiveTransaction()) { 67*795d594fSAndroid Build Coastguard Worker return false; 68*795d594fSAndroid Build Coastguard Worker } 69*795d594fSAndroid Build Coastguard Worker AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 70*795d594fSAndroid Build Coastguard Worker return class_linker->IsTransactionAborted(); 71*795d594fSAndroid Build Coastguard Worker } 72*795d594fSAndroid Build Coastguard Worker 73*795d594fSAndroid Build Coastguard Worker } // namespace art 74