blob: 2698574084e3fd36d687dc7219507516e49c45f5 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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 "driver/compiler_driver.h"
18
Vladimir Marko2c64a832018-01-04 11:31:56 +000019#include <limits>
Brian Carlstrom7940e442013-07-12 13:46:57 -070020#include <stdint.h>
21#include <stdio.h>
Ian Rogers700a4022014-05-19 16:49:03 -070022#include <memory>
Brian Carlstrom7940e442013-07-12 13:46:57 -070023
Mathieu Chartiere401d142015-04-22 13:56:20 -070024#include "art_method-inl.h"
Vladimir Marko2c64a832018-01-04 11:31:56 +000025#include "base/casts.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010026#include "class_linker-inl.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080027#include "common_compiler_test.h"
Mathieu Chartier9e050df2017-08-09 10:05:47 -070028#include "compiler_callbacks.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "dex_file.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080030#include "dex_file_types.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070031#include "gc/heap.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070032#include "handle_scope-inl.h"
33#include "jit/profile_compilation_info.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070034#include "mirror/class-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070035#include "mirror/class_loader.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070036#include "mirror/dex_cache-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070037#include "mirror/object-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070038#include "mirror/object_array-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070039#include "scoped_thread_state_change-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070040
41namespace art {
42
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080043class CompilerDriverTest : public CommonCompilerTest {
Brian Carlstrom7940e442013-07-12 13:46:57 -070044 protected:
Mathieu Chartier90443472015-07-16 20:32:27 -070045 void CompileAll(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
Ian Rogers5fe9af72013-11-14 00:17:20 -080046 TimingLogger timings("CompilerDriverTest::CompileAll", false, false);
Mathieu Chartierf5997b42014-06-20 10:37:54 -070047 TimingLogger::ScopedTiming t(__FUNCTION__, &timings);
Mathieu Chartier72041a02017-07-14 18:23:25 -070048 dex_files_ = GetDexFiles(class_loader);
49 compiler_driver_->SetDexFilesForOatFile(dex_files_);;
50 compiler_driver_->CompileAll(class_loader, dex_files_, &timings);
Mathieu Chartierf5997b42014-06-20 10:37:54 -070051 t.NewTiming("MakeAllExecutable");
Brian Carlstrom7940e442013-07-12 13:46:57 -070052 MakeAllExecutable(class_loader);
53 }
54
55 void EnsureCompiled(jobject class_loader, const char* class_name, const char* method,
56 const char* signature, bool is_virtual)
Mathieu Chartier90443472015-07-16 20:32:27 -070057 REQUIRES(!Locks::mutator_lock_) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070058 CompileAll(class_loader);
59 Thread::Current()->TransitionFromSuspendedToRunnable();
60 bool started = runtime_->Start();
61 CHECK(started);
62 env_ = Thread::Current()->GetJniEnv();
63 class_ = env_->FindClass(class_name);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070064 CHECK(class_ != nullptr) << "Class not found: " << class_name;
Brian Carlstrom7940e442013-07-12 13:46:57 -070065 if (is_virtual) {
66 mid_ = env_->GetMethodID(class_, method, signature);
67 } else {
68 mid_ = env_->GetStaticMethodID(class_, method, signature);
69 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -070070 CHECK(mid_ != nullptr) << "Method not found: " << class_name << "." << method << signature;
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 }
72
73 void MakeAllExecutable(jobject class_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070074 const std::vector<const DexFile*> class_path = GetDexFiles(class_loader);
Brian Carlstrom7940e442013-07-12 13:46:57 -070075 for (size_t i = 0; i != class_path.size(); ++i) {
76 const DexFile* dex_file = class_path[i];
Mathieu Chartier2cebb242015-04-21 16:50:40 -070077 CHECK(dex_file != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 MakeDexFileExecutable(class_loader, *dex_file);
79 }
80 }
81
82 void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) {
83 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
84 for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
85 const DexFile::ClassDef& class_def = dex_file.GetClassDef(i);
86 const char* descriptor = dex_file.GetClassDescriptor(class_def);
87 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070088 StackHandleScope<1> hs(soa.Self());
89 Handle<mirror::ClassLoader> loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -070090 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Ian Rogers98379392014-02-24 16:53:16 -080091 mirror::Class* c = class_linker->FindClass(soa.Self(), descriptor, loader);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070092 CHECK(c != nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -070093 const auto pointer_size = class_linker->GetImagePointerSize();
Alex Lighte64300b2015-12-15 15:02:47 -080094 for (auto& m : c->GetMethods(pointer_size)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070095 MakeExecutable(&m);
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 }
97 }
98 }
99
100 JNIEnv* env_;
101 jclass class_;
102 jmethodID mid_;
Mathieu Chartier72041a02017-07-14 18:23:25 -0700103 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104};
105
106// Disabled due to 10 second runtime on host
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000107// TODO: Update the test for hash-based dex cache arrays. Bug: 30627598
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108TEST_F(CompilerDriverTest, DISABLED_LARGE_CompileDexLibCore) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700109 CompileAll(nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110
111 // All libcore references should resolve
112 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700113 ASSERT_TRUE(java_lang_dex_file_ != nullptr);
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800114 const DexFile& dex = *java_lang_dex_file_;
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700115 ObjPtr<mirror::DexCache> dex_cache = class_linker_->FindDexCache(soa.Self(), dex);
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800116 EXPECT_EQ(dex.NumStringIds(), dex_cache->NumStrings());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 for (size_t i = 0; i < dex_cache->NumStrings(); i++) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800118 const mirror::String* string = dex_cache->GetResolvedString(dex::StringIndex(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700119 EXPECT_TRUE(string != nullptr) << "string_idx=" << i;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 }
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800121 EXPECT_EQ(dex.NumTypeIds(), dex_cache->NumResolvedTypes());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122 for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800123 mirror::Class* type = dex_cache->GetResolvedType(dex::TypeIndex(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700124 EXPECT_TRUE(type != nullptr) << "type_idx=" << i
Andreas Gampea5b09a62016-11-17 15:21:22 -0800125 << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i)));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700126 }
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100127 EXPECT_TRUE(dex_cache->StaticMethodSize() == dex_cache->NumResolvedMethods()
128 || dex.NumMethodIds() == dex_cache->NumResolvedMethods());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700129 auto* cl = Runtime::Current()->GetClassLinker();
130 auto pointer_size = cl->GetImagePointerSize();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700131 for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100132 // FIXME: This is outdated for hash-based method array.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700133 ArtMethod* method = dex_cache->GetResolvedMethod(i, pointer_size);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700134 EXPECT_TRUE(method != nullptr) << "method_idx=" << i
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800135 << " " << dex.GetMethodDeclaringClassDescriptor(dex.GetMethodId(i))
136 << " " << dex.GetMethodName(dex.GetMethodId(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700137 EXPECT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr) << "method_idx=" << i
138 << " " << dex.GetMethodDeclaringClassDescriptor(dex.GetMethodId(i)) << " "
139 << dex.GetMethodName(dex.GetMethodId(i));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140 }
Vladimir Markof44d36c2017-03-14 14:18:46 +0000141 EXPECT_TRUE(dex_cache->StaticArtFieldSize() == dex_cache->NumResolvedFields()
142 || dex.NumFieldIds() == dex_cache->NumResolvedFields());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143 for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) {
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100144 // FIXME: This is outdated for hash-based field array.
Vladimir Markof44d36c2017-03-14 14:18:46 +0000145 ArtField* field = dex_cache->GetResolvedField(i, cl->GetImagePointerSize());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700146 EXPECT_TRUE(field != nullptr) << "field_idx=" << i
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800147 << " " << dex.GetFieldDeclaringClassDescriptor(dex.GetFieldId(i))
148 << " " << dex.GetFieldName(dex.GetFieldId(i));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700149 }
150
151 // TODO check Class::IsVerified for all classes
152
153 // TODO: check that all Method::GetCode() values are non-null
154}
155
Yi Kong5dcf19d2016-04-04 17:44:59 +0100156TEST_F(CompilerDriverTest, AbstractMethodErrorStub) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157 jobject class_loader;
158 {
159 ScopedObjectAccess soa(Thread::Current());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 class_loader = LoadDex("AbstractMethod");
161 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700162 ASSERT_TRUE(class_loader != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700163 EnsureCompiled(class_loader, "AbstractClass", "foo", "()V", true);
164
165 // Create a jobj_ of ConcreteClass, NOT AbstractClass.
166 jclass c_class = env_->FindClass("ConcreteClass");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700167
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 jmethodID constructor = env_->GetMethodID(c_class, "<init>", "()V");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700169
Brian Carlstrom7940e442013-07-12 13:46:57 -0700170 jobject jobj_ = env_->NewObject(c_class, constructor);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700171 ASSERT_TRUE(jobj_ != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700172
173 // Force non-virtual call to AbstractClass foo, will throw AbstractMethodError exception.
174 env_->CallNonvirtualVoidMethod(jobj_, class_, mid_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700175
Brian Carlstrom7940e442013-07-12 13:46:57 -0700176 EXPECT_EQ(env_->ExceptionCheck(), JNI_TRUE);
177 jthrowable exception = env_->ExceptionOccurred();
178 env_->ExceptionClear();
179 jclass jlame = env_->FindClass("java/lang/AbstractMethodError");
180 EXPECT_TRUE(env_->IsInstanceOf(exception, jlame));
Serguei Katkova309d762014-05-26 11:23:39 +0700181 {
182 ScopedObjectAccess soa(Thread::Current());
183 Thread::Current()->ClearException();
184 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185}
186
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700187class CompilerDriverMethodsTest : public CompilerDriverTest {
188 protected:
189 std::unordered_set<std::string>* GetCompiledMethods() OVERRIDE {
190 return new std::unordered_set<std::string>({
191 "byte StaticLeafMethods.identity(byte)",
192 "int StaticLeafMethods.sum(int, int, int)",
193 "double StaticLeafMethods.sum(double, double, double, double)"
194 });
195 }
196};
197
198TEST_F(CompilerDriverMethodsTest, Selection) {
199 Thread* self = Thread::Current();
200 jobject class_loader;
201 {
202 ScopedObjectAccess soa(self);
203 class_loader = LoadDex("StaticLeafMethods");
204 }
205 ASSERT_NE(class_loader, nullptr);
206
207 // Need to enable dex-file writability. Methods rejected to be compiled will run through the
208 // dex-to-dex compiler.
209 for (const DexFile* dex_file : GetDexFiles(class_loader)) {
210 ASSERT_TRUE(dex_file->EnableWrite());
211 }
212
213 CompileAll(class_loader);
214
215 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700216 ScopedObjectAccess soa(self);
Mathieu Chartiered150002015-08-28 11:16:54 -0700217 StackHandleScope<1> hs(self);
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700218 Handle<mirror::ClassLoader> h_loader(
219 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700220 mirror::Class* klass = class_linker->FindClass(self, "LStaticLeafMethods;", h_loader);
221 ASSERT_NE(klass, nullptr);
222
223 std::unique_ptr<std::unordered_set<std::string>> expected(GetCompiledMethods());
224
Mathieu Chartiere401d142015-04-22 13:56:20 -0700225 const auto pointer_size = class_linker->GetImagePointerSize();
226 for (auto& m : klass->GetDirectMethods(pointer_size)) {
David Sehr709b0702016-10-13 09:12:37 -0700227 std::string name = m.PrettyMethod(true);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700228 const void* code = m.GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700229 ASSERT_NE(code, nullptr);
230 if (expected->find(name) != expected->end()) {
231 expected->erase(name);
232 EXPECT_FALSE(class_linker->IsQuickToInterpreterBridge(code));
233 } else {
234 EXPECT_TRUE(class_linker->IsQuickToInterpreterBridge(code));
235 }
236 }
237 EXPECT_TRUE(expected->empty());
238}
239
Calin Juravle877fd962016-01-05 14:29:29 +0000240class CompilerDriverProfileTest : public CompilerDriverTest {
241 protected:
242 ProfileCompilationInfo* GetProfileCompilationInfo() OVERRIDE {
243 ScopedObjectAccess soa(Thread::Current());
244 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("ProfileTestMultiDex");
245
246 ProfileCompilationInfo info;
247 for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
Mathieu Chartierbbe3a5e2017-06-13 16:36:17 -0700248 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
249 MethodReference(dex_file.get(), 1));
250 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
251 MethodReference(dex_file.get(), 2));
Calin Juravle877fd962016-01-05 14:29:29 +0000252 }
253 return &profile_info_;
254 }
255
Mathieu Chartierd0af56c2017-02-17 12:56:25 -0800256 CompilerFilter::Filter GetCompilerFilter() const OVERRIDE {
257 // Use a profile based filter.
258 return CompilerFilter::kSpeedProfile;
259 }
260
Calin Juravle877fd962016-01-05 14:29:29 +0000261 std::unordered_set<std::string> GetExpectedMethodsForClass(const std::string& clazz) {
262 if (clazz == "Main") {
263 return std::unordered_set<std::string>({
264 "java.lang.String Main.getA()",
265 "java.lang.String Main.getB()"});
266 } else if (clazz == "Second") {
267 return std::unordered_set<std::string>({
268 "java.lang.String Second.getX()",
269 "java.lang.String Second.getY()"});
270 } else {
271 return std::unordered_set<std::string>();
272 }
273 }
274
275 void CheckCompiledMethods(jobject class_loader,
276 const std::string& clazz,
277 const std::unordered_set<std::string>& expected_methods) {
278 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
279 Thread* self = Thread::Current();
280 ScopedObjectAccess soa(self);
281 StackHandleScope<1> hs(self);
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700282 Handle<mirror::ClassLoader> h_loader(
283 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Calin Juravle877fd962016-01-05 14:29:29 +0000284 mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
285 ASSERT_NE(klass, nullptr);
286
287 const auto pointer_size = class_linker->GetImagePointerSize();
288 size_t number_of_compiled_methods = 0;
289 for (auto& m : klass->GetVirtualMethods(pointer_size)) {
David Sehr709b0702016-10-13 09:12:37 -0700290 std::string name = m.PrettyMethod(true);
Calin Juravle877fd962016-01-05 14:29:29 +0000291 const void* code = m.GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
292 ASSERT_NE(code, nullptr);
293 if (expected_methods.find(name) != expected_methods.end()) {
294 number_of_compiled_methods++;
295 EXPECT_FALSE(class_linker->IsQuickToInterpreterBridge(code));
296 } else {
297 EXPECT_TRUE(class_linker->IsQuickToInterpreterBridge(code));
298 }
299 }
300 EXPECT_EQ(expected_methods.size(), number_of_compiled_methods);
301 }
302
303 private:
304 ProfileCompilationInfo profile_info_;
305};
306
307TEST_F(CompilerDriverProfileTest, ProfileGuidedCompilation) {
Calin Juravle877fd962016-01-05 14:29:29 +0000308 Thread* self = Thread::Current();
309 jobject class_loader;
310 {
311 ScopedObjectAccess soa(self);
312 class_loader = LoadDex("ProfileTestMultiDex");
313 }
314 ASSERT_NE(class_loader, nullptr);
315
316 // Need to enable dex-file writability. Methods rejected to be compiled will run through the
317 // dex-to-dex compiler.
Calin Juravle877fd962016-01-05 14:29:29 +0000318 for (const DexFile* dex_file : GetDexFiles(class_loader)) {
319 ASSERT_TRUE(dex_file->EnableWrite());
320 }
321
322 CompileAll(class_loader);
323
324 std::unordered_set<std::string> m = GetExpectedMethodsForClass("Main");
325 std::unordered_set<std::string> s = GetExpectedMethodsForClass("Second");
326 CheckCompiledMethods(class_loader, "LMain;", m);
327 CheckCompiledMethods(class_loader, "LSecond;", s);
328}
329
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100330// Test that a verify only compiler filter updates the CompiledClass map,
331// which will be used for OatClass.
332class CompilerDriverVerifyTest : public CompilerDriverTest {
333 protected:
334 CompilerFilter::Filter GetCompilerFilter() const OVERRIDE {
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100335 return CompilerFilter::kVerify;
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100336 }
337
338 void CheckVerifiedClass(jobject class_loader, const std::string& clazz) const {
339 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
340 Thread* self = Thread::Current();
341 ScopedObjectAccess soa(self);
342 StackHandleScope<1> hs(self);
343 Handle<mirror::ClassLoader> h_loader(
344 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
345 mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
346 ASSERT_NE(klass, nullptr);
347 EXPECT_TRUE(klass->IsVerified());
348
Vladimir Marko2c64a832018-01-04 11:31:56 +0000349 ClassStatus status;
Andreas Gampebb846102017-05-11 21:03:35 -0700350 bool found = compiler_driver_->GetCompiledClass(
351 ClassReference(&klass->GetDexFile(), klass->GetDexTypeIndex().index_), &status);
352 ASSERT_TRUE(found);
Vladimir Marko2c64a832018-01-04 11:31:56 +0000353 EXPECT_EQ(status, ClassStatus::kVerified);
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100354 }
355};
356
357TEST_F(CompilerDriverVerifyTest, VerifyCompilation) {
358 Thread* self = Thread::Current();
359 jobject class_loader;
360 {
361 ScopedObjectAccess soa(self);
362 class_loader = LoadDex("ProfileTestMultiDex");
363 }
364 ASSERT_NE(class_loader, nullptr);
365
366 CompileAll(class_loader);
367
368 CheckVerifiedClass(class_loader, "LMain;");
369 CheckVerifiedClass(class_loader, "LSecond;");
370}
371
Vladimir Marko2c64a832018-01-04 11:31:56 +0000372// Test that a class of status ClassStatus::kRetryVerificationAtRuntime is indeed
373// recorded that way in the driver.
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700374TEST_F(CompilerDriverVerifyTest, RetryVerifcationStatusCheckVerified) {
Jeff Haof1aa2652017-08-03 17:09:33 -0700375 Thread* const self = Thread::Current();
376 jobject class_loader;
377 std::vector<const DexFile*> dex_files;
378 const DexFile* dex_file = nullptr;
379 {
380 ScopedObjectAccess soa(self);
381 class_loader = LoadDex("ProfileTestMultiDex");
382 ASSERT_NE(class_loader, nullptr);
383 dex_files = GetDexFiles(class_loader);
384 ASSERT_GT(dex_files.size(), 0u);
385 dex_file = dex_files.front();
386 }
387 compiler_driver_->SetDexFilesForOatFile(dex_files);
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700388 callbacks_->SetDoesClassUnloading(true, compiler_driver_.get());
Jeff Haof1aa2652017-08-03 17:09:33 -0700389 ClassReference ref(dex_file, 0u);
390 // Test that the status is read from the compiler driver as expected.
Vladimir Marko2c64a832018-01-04 11:31:56 +0000391 static_assert(enum_cast<size_t>(ClassStatus::kLast) < std::numeric_limits<size_t>::max(),
392 "Make sure incrementing the class status does not overflow.");
393 for (size_t i = enum_cast<size_t>(ClassStatus::kRetryVerificationAtRuntime);
394 i <= enum_cast<size_t>(ClassStatus::kLast);
395 ++i) {
396 const ClassStatus expected_status = enum_cast<ClassStatus>(i);
Jeff Haof1aa2652017-08-03 17:09:33 -0700397 // Skip unsupported status that are not supposed to be ever recorded.
Vladimir Marko2c64a832018-01-04 11:31:56 +0000398 if (expected_status == ClassStatus::kVerifyingAtRuntime ||
399 expected_status == ClassStatus::kInitializing) {
Jeff Haof1aa2652017-08-03 17:09:33 -0700400 continue;
401 }
402 compiler_driver_->RecordClassStatus(ref, expected_status);
Vladimir Marko2c64a832018-01-04 11:31:56 +0000403 ClassStatus status = {};
Jeff Haof1aa2652017-08-03 17:09:33 -0700404 ASSERT_TRUE(compiler_driver_->GetCompiledClass(ref, &status));
405 EXPECT_EQ(status, expected_status);
406 }
407}
408
Brian Carlstrom7940e442013-07-12 13:46:57 -0700409// TODO: need check-cast test (when stub complete & we can throw/catch
410
411} // namespace art