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 {} 36 GetVerifierDeps() const37 verifier::VerifierDeps* GetVerifierDeps() const override { return nullptr; } 38 39 private: 40 DISALLOW_COPY_AND_ASSIGN(CommonTransactionTestCompilerCallbacks); 41 }; 42 CreateCompilerCallbacks()43CompilerCallbacks* CommonTransactionTestImpl::CreateCompilerCallbacks() { 44 return new CommonTransactionTestCompilerCallbacks(); 45 } 46 EnterTransactionMode()47void CommonTransactionTestImpl::EnterTransactionMode() { 48 CHECK(!Runtime::Current()->IsActiveTransaction()); 49 AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 50 class_linker->EnterTransactionMode(/*strict=*/ false, /*root=*/ nullptr); 51 } 52 ExitTransactionMode()53void CommonTransactionTestImpl::ExitTransactionMode() { 54 AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 55 class_linker->ExitTransactionMode(); 56 CHECK(!Runtime::Current()->IsActiveTransaction()); 57 } 58 RollbackAndExitTransactionMode()59void CommonTransactionTestImpl::RollbackAndExitTransactionMode() { 60 AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 61 class_linker->RollbackAndExitTransactionMode(); 62 CHECK(!Runtime::Current()->IsActiveTransaction()); 63 } 64 IsTransactionAborted()65bool CommonTransactionTestImpl::IsTransactionAborted() { 66 if (!Runtime::Current()->IsActiveTransaction()) { 67 return false; 68 } 69 AotClassLinker* class_linker = down_cast<AotClassLinker*>(Runtime::Current()->GetClassLinker()); 70 return class_linker->IsTransactionAborted(); 71 } 72 73 } // namespace art 74