blob: 9396565eee3760d4046dc5a328b74047911ff2b2 [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
Mathieu Chartier9e050df2017-08-09 10:05:47 -070019#include "class_reference.h"
20#include "compiler_callbacks.h"
Chang Xing605fe242017-07-20 15:57:21 -070021#include "handle_scope-inl.h"
Mathieu Chartier9e050df2017-08-09 10:05:47 -070022#include "mirror/class-inl.h"
Chang Xing605fe242017-07-20 15:57:21 -070023#include "runtime.h"
Mathieu Chartier9e050df2017-08-09 10:05:47 -070024#include "verifier/verifier_enums.h"
Chang Xing605fe242017-07-20 15:57:21 -070025
26namespace art {
27
28AotClassLinker::AotClassLinker(InternTable *intern_table) : ClassLinker(intern_table) {}
29
30AotClassLinker::~AotClassLinker() {}
31
32// Wrap the original InitializeClass with creation of transaction when in strict mode.
33bool AotClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass,
34 bool can_init_statics, bool can_init_parents) {
35 Runtime* const runtime = Runtime::Current();
Chang Xingadbb91c2017-07-17 11:23:55 -070036 bool strict_mode_ = runtime->IsActiveStrictTransactionMode();
Chang Xing605fe242017-07-20 15:57:21 -070037
38 DCHECK(klass != nullptr);
39 if (klass->IsInitialized() || klass->IsInitializing()) {
40 return ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents);
41 }
42
Chang Xingadbb91c2017-07-17 11:23:55 -070043 // Don't initialize klass if it's superclass is not initialized, because superclass might abort
44 // the transaction and rolled back after klass's change is commited.
45 if (strict_mode_ && !klass->IsInterface() && klass->HasSuperClass()) {
46 if (klass->GetSuperClass()->GetStatus() == mirror::Class::kStatusInitializing) {
47 runtime->AbortTransactionAndThrowAbortError(self, "Can't resolve "
48 + klass->PrettyTypeOf() + " because it's superclass is not initialized.");
49 return false;
50 }
51 }
52
53 if (strict_mode_) {
Chang Xing605fe242017-07-20 15:57:21 -070054 runtime->EnterTransactionMode(true, klass.Get()->AsClass());
55 }
56 bool success = ClassLinker::InitializeClass(self, klass, can_init_statics, can_init_parents);
57
Chang Xingadbb91c2017-07-17 11:23:55 -070058 if (strict_mode_) {
Chang Xing605fe242017-07-20 15:57:21 -070059 if (success) {
60 // Exit Transaction if success.
61 runtime->ExitTransactionMode();
62 } else {
Nicolas Geoffrayabadf022017-08-03 08:25:41 +000063 // If not successfully initialized, the last transaction must abort. Don't rollback
64 // immediately, leave the cleanup to compiler driver which needs abort message and exception.
65 DCHECK(runtime->IsTransactionAborted());
Chang Xing605fe242017-07-20 15:57:21 -070066 DCHECK(self->IsExceptionPending());
67 }
68 }
69 return success;
70}
Mathieu Chartier9e050df2017-08-09 10:05:47 -070071
72verifier::FailureKind AotClassLinker::PerformClassVerification(Thread* self,
73 Handle<mirror::Class> klass,
74 verifier::HardFailLogMode log_level,
75 std::string* error_msg) {
76 Runtime* const runtime = Runtime::Current();
77 CompilerCallbacks* callbacks = runtime->GetCompilerCallbacks();
78 if (callbacks->CanAssumeVerified(ClassReference(&klass->GetDexFile(),
79 klass->GetDexClassDefIndex()))) {
80 return verifier::FailureKind::kNoFailure;
81 }
82 return ClassLinker::PerformClassVerification(self, klass, log_level, error_msg);
83}
84
Chang Xing605fe242017-07-20 15:57:21 -070085} // namespace art