Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "aot_class_linker.h" |
| 18 | |
| 19 | #include "handle_scope-inl.h" |
| 20 | #include "mirror/class.h" |
| 21 | #include "mirror/object-inl.h" |
| 22 | #include "runtime.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | AotClassLinker::AotClassLinker(InternTable *intern_table) : ClassLinker(intern_table) {} |
| 27 | |
| 28 | AotClassLinker::~AotClassLinker() {} |
| 29 | |
| 30 | // Wrap the original InitializeClass with creation of transaction when in strict mode. |
| 31 | bool AotClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass, |
| 32 | bool can_init_statics, bool can_init_parents) { |
| 33 | Runtime* const runtime = Runtime::Current(); |
| 34 | |
| 35 | DCHECK(klass != nullptr); |
| 36 | if (klass->IsInitialized() || klass->IsInitializing()) { |
| 37 | return ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents); |
| 38 | } |
| 39 | |
| 40 | if (runtime->IsActiveStrictTransactionMode()) { |
| 41 | runtime->EnterTransactionMode(true, klass.Get()->AsClass()); |
| 42 | } |
| 43 | bool success = ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents); |
| 44 | |
| 45 | if (runtime->IsActiveStrictTransactionMode()) { |
| 46 | if (success) { |
| 47 | // Exit Transaction if success. |
| 48 | runtime->ExitTransactionMode(); |
| 49 | } else { |
| 50 | // If not successfully initialized, the last transaction must abort. Don't rollback |
| 51 | // immediately, leave the cleanup to compiler driver which needs abort message and exception. |
| 52 | DCHECK(runtime->IsTransactionAborted()); |
| 53 | DCHECK(self->IsExceptionPending()); |
| 54 | } |
| 55 | } |
| 56 | return success; |
| 57 | } |
| 58 | } // namespace art |