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