blob: b1bc3f8f2e38163985d40b988a52885c73746775 [file] [log] [blame]
Chang Xing605fe242017-07-20 15:57:21 -07001/*
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
24namespace art {
25
26AotClassLinker::AotClassLinker(InternTable *intern_table) : ClassLinker(intern_table) {}
27
28AotClassLinker::~AotClassLinker() {}
29
30// Wrap the original InitializeClass with creation of transaction when in strict mode.
31bool AotClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass,
32 bool can_init_statics, bool can_init_parents) {
33 Runtime* const runtime = Runtime::Current();
Chang Xingadbb91c2017-07-17 11:23:55 -070034 bool strict_mode_ = runtime->IsActiveStrictTransactionMode();
Chang Xing605fe242017-07-20 15:57:21 -070035
36 DCHECK(klass != nullptr);
37 if (klass->IsInitialized() || klass->IsInitializing()) {
38 return ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents);
39 }
40
Chang Xingadbb91c2017-07-17 11:23:55 -070041 // Don't initialize klass if it's superclass is not initialized, because superclass might abort
42 // the transaction and rolled back after klass's change is commited.
43 if (strict_mode_ && !klass->IsInterface() && klass->HasSuperClass()) {
44 if (klass->GetSuperClass()->GetStatus() == mirror::Class::kStatusInitializing) {
45 runtime->AbortTransactionAndThrowAbortError(self, "Can't resolve "
46 + klass->PrettyTypeOf() + " because it's superclass is not initialized.");
47 return false;
48 }
49 }
50
51 if (strict_mode_) {
Chang Xing605fe242017-07-20 15:57:21 -070052 runtime->EnterTransactionMode(true, klass.Get()->AsClass());
53 }
54 bool success = ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents);
55
Chang Xingadbb91c2017-07-17 11:23:55 -070056 if (strict_mode_) {
Chang Xing605fe242017-07-20 15:57:21 -070057 if (success) {
58 // Exit Transaction if success.
59 runtime->ExitTransactionMode();
60 } else {
61 // If not successfully initialized, the last transaction must abort. Don't rollback
62 // immediately, leave the cleanup to compiler driver which needs abort message and exception.
63 DCHECK(runtime->IsTransactionAborted());
64 DCHECK(self->IsExceptionPending());
65 }
66 }
67 return success;
68}
69} // namespace art