blob: 278358b250142aaafd55b223384eb5d1ee1fb59f [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
19#include <stdint.h>
20#include <stdio.h>
Ian Rogers700a4022014-05-19 16:49:03 -070021#include <memory>
Brian Carlstrom7940e442013-07-12 13:46:57 -070022
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "art_method-inl.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010024#include "class_linker-inl.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080025#include "common_compiler_test.h"
Mathieu Chartier9e050df2017-08-09 10:05:47 -070026#include "compiler_callbacks.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "dex_file.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080028#include "dex_file_types.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "gc/heap.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070030#include "handle_scope-inl.h"
31#include "jit/profile_compilation_info.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032#include "mirror/class-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070033#include "mirror/class_loader.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070034#include "mirror/dex_cache-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070035#include "mirror/object-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070036#include "mirror/object_array-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070037#include "scoped_thread_state_change-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070038
39namespace art {
40
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080041class CompilerDriverTest : public CommonCompilerTest {
Brian Carlstrom7940e442013-07-12 13:46:57 -070042 protected:
Mathieu Chartier90443472015-07-16 20:32:27 -070043 void CompileAll(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
Ian Rogers5fe9af72013-11-14 00:17:20 -080044 TimingLogger timings("CompilerDriverTest::CompileAll", false, false);
Mathieu Chartierf5997b42014-06-20 10:37:54 -070045 TimingLogger::ScopedTiming t(__FUNCTION__, &timings);
Mathieu Chartier72041a02017-07-14 18:23:25 -070046 dex_files_ = GetDexFiles(class_loader);
47 compiler_driver_->SetDexFilesForOatFile(dex_files_);;
48 compiler_driver_->CompileAll(class_loader, dex_files_, &timings);
Mathieu Chartierf5997b42014-06-20 10:37:54 -070049 t.NewTiming("MakeAllExecutable");
Brian Carlstrom7940e442013-07-12 13:46:57 -070050 MakeAllExecutable(class_loader);
51 }
52
53 void EnsureCompiled(jobject class_loader, const char* class_name, const char* method,
54 const char* signature, bool is_virtual)
Mathieu Chartier90443472015-07-16 20:32:27 -070055 REQUIRES(!Locks::mutator_lock_) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070056 CompileAll(class_loader);
57 Thread::Current()->TransitionFromSuspendedToRunnable();
58 bool started = runtime_->Start();
59 CHECK(started);
60 env_ = Thread::Current()->GetJniEnv();
61 class_ = env_->FindClass(class_name);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070062 CHECK(class_ != nullptr) << "Class not found: " << class_name;
Brian Carlstrom7940e442013-07-12 13:46:57 -070063 if (is_virtual) {
64 mid_ = env_->GetMethodID(class_, method, signature);
65 } else {
66 mid_ = env_->GetStaticMethodID(class_, method, signature);
67 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -070068 CHECK(mid_ != nullptr) << "Method not found: " << class_name << "." << method << signature;
Brian Carlstrom7940e442013-07-12 13:46:57 -070069 }
70
71 void MakeAllExecutable(jobject class_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070072 const std::vector<const DexFile*> class_path = GetDexFiles(class_loader);
Brian Carlstrom7940e442013-07-12 13:46:57 -070073 for (size_t i = 0; i != class_path.size(); ++i) {
74 const DexFile* dex_file = class_path[i];
Mathieu Chartier2cebb242015-04-21 16:50:40 -070075 CHECK(dex_file != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070076 MakeDexFileExecutable(class_loader, *dex_file);
77 }
78 }
79
80 void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) {
81 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
82 for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
83 const DexFile::ClassDef& class_def = dex_file.GetClassDef(i);
84 const char* descriptor = dex_file.GetClassDescriptor(class_def);
85 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070086 StackHandleScope<1> hs(soa.Self());
87 Handle<mirror::ClassLoader> loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -070088 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Ian Rogers98379392014-02-24 16:53:16 -080089 mirror::Class* c = class_linker->FindClass(soa.Self(), descriptor, loader);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070090 CHECK(c != nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -070091 const auto pointer_size = class_linker->GetImagePointerSize();
Alex Lighte64300b2015-12-15 15:02:47 -080092 for (auto& m : c->GetMethods(pointer_size)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070093 MakeExecutable(&m);
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 }
95 }
96 }
97
98 JNIEnv* env_;
99 jclass class_;
100 jmethodID mid_;
Mathieu Chartier72041a02017-07-14 18:23:25 -0700101 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700102};
103
104// Disabled due to 10 second runtime on host
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000105// TODO: Update the test for hash-based dex cache arrays. Bug: 30627598
Brian Carlstrom7940e442013-07-12 13:46:57 -0700106TEST_F(CompilerDriverTest, DISABLED_LARGE_CompileDexLibCore) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700107 CompileAll(nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108
109 // All libcore references should resolve
110 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700111 ASSERT_TRUE(java_lang_dex_file_ != nullptr);
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800112 const DexFile& dex = *java_lang_dex_file_;
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700113 ObjPtr<mirror::DexCache> dex_cache = class_linker_->FindDexCache(soa.Self(), dex);
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800114 EXPECT_EQ(dex.NumStringIds(), dex_cache->NumStrings());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 for (size_t i = 0; i < dex_cache->NumStrings(); i++) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800116 const mirror::String* string = dex_cache->GetResolvedString(dex::StringIndex(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700117 EXPECT_TRUE(string != nullptr) << "string_idx=" << i;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 }
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800119 EXPECT_EQ(dex.NumTypeIds(), dex_cache->NumResolvedTypes());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800121 mirror::Class* type = dex_cache->GetResolvedType(dex::TypeIndex(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700122 EXPECT_TRUE(type != nullptr) << "type_idx=" << i
Andreas Gampea5b09a62016-11-17 15:21:22 -0800123 << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i)));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124 }
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100125 EXPECT_TRUE(dex_cache->StaticMethodSize() == dex_cache->NumResolvedMethods()
126 || dex.NumMethodIds() == dex_cache->NumResolvedMethods());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700127 auto* cl = Runtime::Current()->GetClassLinker();
128 auto pointer_size = cl->GetImagePointerSize();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129 for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100130 // FIXME: This is outdated for hash-based method array.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700131 ArtMethod* method = dex_cache->GetResolvedMethod(i, pointer_size);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700132 EXPECT_TRUE(method != nullptr) << "method_idx=" << i
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800133 << " " << dex.GetMethodDeclaringClassDescriptor(dex.GetMethodId(i))
134 << " " << dex.GetMethodName(dex.GetMethodId(i));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700135 EXPECT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr) << "method_idx=" << i
136 << " " << dex.GetMethodDeclaringClassDescriptor(dex.GetMethodId(i)) << " "
137 << dex.GetMethodName(dex.GetMethodId(i));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700138 }
Vladimir Markof44d36c2017-03-14 14:18:46 +0000139 EXPECT_TRUE(dex_cache->StaticArtFieldSize() == dex_cache->NumResolvedFields()
140 || dex.NumFieldIds() == dex_cache->NumResolvedFields());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141 for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) {
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100142 // FIXME: This is outdated for hash-based field array.
Vladimir Markof44d36c2017-03-14 14:18:46 +0000143 ArtField* field = dex_cache->GetResolvedField(i, cl->GetImagePointerSize());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700144 EXPECT_TRUE(field != nullptr) << "field_idx=" << i
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800145 << " " << dex.GetFieldDeclaringClassDescriptor(dex.GetFieldId(i))
146 << " " << dex.GetFieldName(dex.GetFieldId(i));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700147 }
148
149 // TODO check Class::IsVerified for all classes
150
151 // TODO: check that all Method::GetCode() values are non-null
152}
153
Yi Kong5dcf19d2016-04-04 17:44:59 +0100154TEST_F(CompilerDriverTest, AbstractMethodErrorStub) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700155 jobject class_loader;
156 {
157 ScopedObjectAccess soa(Thread::Current());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700158 class_loader = LoadDex("AbstractMethod");
159 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700160 ASSERT_TRUE(class_loader != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 EnsureCompiled(class_loader, "AbstractClass", "foo", "()V", true);
162
163 // Create a jobj_ of ConcreteClass, NOT AbstractClass.
164 jclass c_class = env_->FindClass("ConcreteClass");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700165
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166 jmethodID constructor = env_->GetMethodID(c_class, "<init>", "()V");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700167
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 jobject jobj_ = env_->NewObject(c_class, constructor);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700169 ASSERT_TRUE(jobj_ != nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700170
171 // Force non-virtual call to AbstractClass foo, will throw AbstractMethodError exception.
172 env_->CallNonvirtualVoidMethod(jobj_, class_, mid_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700173
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 EXPECT_EQ(env_->ExceptionCheck(), JNI_TRUE);
175 jthrowable exception = env_->ExceptionOccurred();
176 env_->ExceptionClear();
177 jclass jlame = env_->FindClass("java/lang/AbstractMethodError");
178 EXPECT_TRUE(env_->IsInstanceOf(exception, jlame));
Serguei Katkova309d762014-05-26 11:23:39 +0700179 {
180 ScopedObjectAccess soa(Thread::Current());
181 Thread::Current()->ClearException();
182 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700183}
184
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700185class CompilerDriverMethodsTest : public CompilerDriverTest {
186 protected:
187 std::unordered_set<std::string>* GetCompiledMethods() OVERRIDE {
188 return new std::unordered_set<std::string>({
189 "byte StaticLeafMethods.identity(byte)",
190 "int StaticLeafMethods.sum(int, int, int)",
191 "double StaticLeafMethods.sum(double, double, double, double)"
192 });
193 }
194};
195
196TEST_F(CompilerDriverMethodsTest, Selection) {
197 Thread* self = Thread::Current();
198 jobject class_loader;
199 {
200 ScopedObjectAccess soa(self);
201 class_loader = LoadDex("StaticLeafMethods");
202 }
203 ASSERT_NE(class_loader, nullptr);
204
205 // Need to enable dex-file writability. Methods rejected to be compiled will run through the
206 // dex-to-dex compiler.
207 for (const DexFile* dex_file : GetDexFiles(class_loader)) {
208 ASSERT_TRUE(dex_file->EnableWrite());
209 }
210
211 CompileAll(class_loader);
212
213 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700214 ScopedObjectAccess soa(self);
Mathieu Chartiered150002015-08-28 11:16:54 -0700215 StackHandleScope<1> hs(self);
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700216 Handle<mirror::ClassLoader> h_loader(
217 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700218 mirror::Class* klass = class_linker->FindClass(self, "LStaticLeafMethods;", h_loader);
219 ASSERT_NE(klass, nullptr);
220
221 std::unique_ptr<std::unordered_set<std::string>> expected(GetCompiledMethods());
222
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 const auto pointer_size = class_linker->GetImagePointerSize();
224 for (auto& m : klass->GetDirectMethods(pointer_size)) {
David Sehr709b0702016-10-13 09:12:37 -0700225 std::string name = m.PrettyMethod(true);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700226 const void* code = m.GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
Andreas Gampe70bef0d2015-04-15 02:37:28 -0700227 ASSERT_NE(code, nullptr);
228 if (expected->find(name) != expected->end()) {
229 expected->erase(name);
230 EXPECT_FALSE(class_linker->IsQuickToInterpreterBridge(code));
231 } else {
232 EXPECT_TRUE(class_linker->IsQuickToInterpreterBridge(code));
233 }
234 }
235 EXPECT_TRUE(expected->empty());
236}
237
Calin Juravle877fd962016-01-05 14:29:29 +0000238class CompilerDriverProfileTest : public CompilerDriverTest {
239 protected:
240 ProfileCompilationInfo* GetProfileCompilationInfo() OVERRIDE {
241 ScopedObjectAccess soa(Thread::Current());
242 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("ProfileTestMultiDex");
243
244 ProfileCompilationInfo info;
245 for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
Mathieu Chartierbbe3a5e2017-06-13 16:36:17 -0700246 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
247 MethodReference(dex_file.get(), 1));
248 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
249 MethodReference(dex_file.get(), 2));
Calin Juravle877fd962016-01-05 14:29:29 +0000250 }
251 return &profile_info_;
252 }
253
Mathieu Chartierd0af56c2017-02-17 12:56:25 -0800254 CompilerFilter::Filter GetCompilerFilter() const OVERRIDE {
255 // Use a profile based filter.
256 return CompilerFilter::kSpeedProfile;
257 }
258
Calin Juravle877fd962016-01-05 14:29:29 +0000259 std::unordered_set<std::string> GetExpectedMethodsForClass(const std::string& clazz) {
260 if (clazz == "Main") {
261 return std::unordered_set<std::string>({
262 "java.lang.String Main.getA()",
263 "java.lang.String Main.getB()"});
264 } else if (clazz == "Second") {
265 return std::unordered_set<std::string>({
266 "java.lang.String Second.getX()",
267 "java.lang.String Second.getY()"});
268 } else {
269 return std::unordered_set<std::string>();
270 }
271 }
272
273 void CheckCompiledMethods(jobject class_loader,
274 const std::string& clazz,
275 const std::unordered_set<std::string>& expected_methods) {
276 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
277 Thread* self = Thread::Current();
278 ScopedObjectAccess soa(self);
279 StackHandleScope<1> hs(self);
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700280 Handle<mirror::ClassLoader> h_loader(
281 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Calin Juravle877fd962016-01-05 14:29:29 +0000282 mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
283 ASSERT_NE(klass, nullptr);
284
285 const auto pointer_size = class_linker->GetImagePointerSize();
286 size_t number_of_compiled_methods = 0;
287 for (auto& m : klass->GetVirtualMethods(pointer_size)) {
David Sehr709b0702016-10-13 09:12:37 -0700288 std::string name = m.PrettyMethod(true);
Calin Juravle877fd962016-01-05 14:29:29 +0000289 const void* code = m.GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
290 ASSERT_NE(code, nullptr);
291 if (expected_methods.find(name) != expected_methods.end()) {
292 number_of_compiled_methods++;
293 EXPECT_FALSE(class_linker->IsQuickToInterpreterBridge(code));
294 } else {
295 EXPECT_TRUE(class_linker->IsQuickToInterpreterBridge(code));
296 }
297 }
298 EXPECT_EQ(expected_methods.size(), number_of_compiled_methods);
299 }
300
301 private:
302 ProfileCompilationInfo profile_info_;
303};
304
305TEST_F(CompilerDriverProfileTest, ProfileGuidedCompilation) {
Calin Juravle877fd962016-01-05 14:29:29 +0000306 Thread* self = Thread::Current();
307 jobject class_loader;
308 {
309 ScopedObjectAccess soa(self);
310 class_loader = LoadDex("ProfileTestMultiDex");
311 }
312 ASSERT_NE(class_loader, nullptr);
313
314 // Need to enable dex-file writability. Methods rejected to be compiled will run through the
315 // dex-to-dex compiler.
Calin Juravle877fd962016-01-05 14:29:29 +0000316 for (const DexFile* dex_file : GetDexFiles(class_loader)) {
317 ASSERT_TRUE(dex_file->EnableWrite());
318 }
319
320 CompileAll(class_loader);
321
322 std::unordered_set<std::string> m = GetExpectedMethodsForClass("Main");
323 std::unordered_set<std::string> s = GetExpectedMethodsForClass("Second");
324 CheckCompiledMethods(class_loader, "LMain;", m);
325 CheckCompiledMethods(class_loader, "LSecond;", s);
326}
327
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100328// Test that a verify only compiler filter updates the CompiledClass map,
329// which will be used for OatClass.
330class CompilerDriverVerifyTest : public CompilerDriverTest {
331 protected:
332 CompilerFilter::Filter GetCompilerFilter() const OVERRIDE {
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100333 return CompilerFilter::kVerify;
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100334 }
335
336 void CheckVerifiedClass(jobject class_loader, const std::string& clazz) const {
337 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
338 Thread* self = Thread::Current();
339 ScopedObjectAccess soa(self);
340 StackHandleScope<1> hs(self);
341 Handle<mirror::ClassLoader> h_loader(
342 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
343 mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
344 ASSERT_NE(klass, nullptr);
345 EXPECT_TRUE(klass->IsVerified());
346
Andreas Gampebb846102017-05-11 21:03:35 -0700347 mirror::Class::Status status;
348 bool found = compiler_driver_->GetCompiledClass(
349 ClassReference(&klass->GetDexFile(), klass->GetDexTypeIndex().index_), &status);
350 ASSERT_TRUE(found);
351 EXPECT_EQ(status, mirror::Class::kStatusVerified);
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100352 }
353};
354
355TEST_F(CompilerDriverVerifyTest, VerifyCompilation) {
356 Thread* self = Thread::Current();
357 jobject class_loader;
358 {
359 ScopedObjectAccess soa(self);
360 class_loader = LoadDex("ProfileTestMultiDex");
361 }
362 ASSERT_NE(class_loader, nullptr);
363
364 CompileAll(class_loader);
365
366 CheckVerifiedClass(class_loader, "LMain;");
367 CheckVerifiedClass(class_loader, "LSecond;");
368}
369
Jeff Haof1aa2652017-08-03 17:09:33 -0700370// Test that a class of status kStatusRetryVerificationAtRuntime is indeed recorded that way in the
371// driver.
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700372TEST_F(CompilerDriverVerifyTest, RetryVerifcationStatusCheckVerified) {
Jeff Haof1aa2652017-08-03 17:09:33 -0700373 Thread* const self = Thread::Current();
374 jobject class_loader;
375 std::vector<const DexFile*> dex_files;
376 const DexFile* dex_file = nullptr;
377 {
378 ScopedObjectAccess soa(self);
379 class_loader = LoadDex("ProfileTestMultiDex");
380 ASSERT_NE(class_loader, nullptr);
381 dex_files = GetDexFiles(class_loader);
382 ASSERT_GT(dex_files.size(), 0u);
383 dex_file = dex_files.front();
384 }
385 compiler_driver_->SetDexFilesForOatFile(dex_files);
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700386 callbacks_->SetDoesClassUnloading(true, compiler_driver_.get());
Jeff Haof1aa2652017-08-03 17:09:33 -0700387 ClassReference ref(dex_file, 0u);
388 // Test that the status is read from the compiler driver as expected.
389 for (size_t i = mirror::Class::kStatusRetryVerificationAtRuntime;
390 i < mirror::Class::kStatusMax;
391 ++i) {
392 const mirror::Class::Status expected_status = static_cast<mirror::Class::Status>(i);
393 // Skip unsupported status that are not supposed to be ever recorded.
394 if (expected_status == mirror::Class::kStatusVerifyingAtRuntime ||
395 expected_status == mirror::Class::kStatusInitializing) {
396 continue;
397 }
398 compiler_driver_->RecordClassStatus(ref, expected_status);
399 mirror::Class::Status status = {};
400 ASSERT_TRUE(compiler_driver_->GetCompiledClass(ref, &status));
401 EXPECT_EQ(status, expected_status);
402 }
403}
404
Brian Carlstrom7940e442013-07-12 13:46:57 -0700405// TODO: need check-cast test (when stub complete & we can throw/catch
406
407} // namespace art