blob: e73d0724c9aa116ab31bc97979e817c41cf43cff [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"
David Sehr9e734c72018-01-04 17:56:19 -080029#include "dex/dex_file.h"
30#include "dex/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"
Brian Carlstrom7940e442013-07-12 13:46:57 -070033#include "mirror/class-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070034#include "mirror/class_loader.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070035#include "mirror/dex_cache-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070036#include "mirror/object-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070037#include "mirror/object_array-inl.h"
David Sehr82d046e2018-04-23 08:14:19 -070038#include "profile/profile_compilation_info.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:
Vladimir Marko2afaff72018-11-30 17:01:50 +000045 void CompileAllAndMakeExecutable(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
46 TimingLogger timings("CompilerDriverTest::CompileAllAndMakeExecutable", false, false);
Mathieu Chartier72041a02017-07-14 18:23:25 -070047 dex_files_ = GetDexFiles(class_loader);
Vladimir Marko2afaff72018-11-30 17:01:50 +000048 CompileAll(class_loader, dex_files_, &timings);
49 TimingLogger::ScopedTiming t("MakeAllExecutable", &timings);
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_) {
Vladimir Marko2afaff72018-11-30 17:01:50 +000056 CompileAllAndMakeExecutable(class_loader);
Brian Carlstrom7940e442013-07-12 13:46:57 -070057 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++) {
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080083 const dex::ClassDef& class_def = dex_file.GetClassDef(i);
Brian Carlstrom7940e442013-07-12 13:46:57 -070084 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)));
Vladimir Markoa8bba7d2018-05-30 15:18:48 +010089 ObjPtr<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) {
Vladimir Marko2afaff72018-11-30 17:01:50 +0000107 CompileAllAndMakeExecutable(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++) {
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100116 const ObjPtr<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++) {
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100121 const ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(dex::TypeIndex(i));
122 EXPECT_TRUE(type != nullptr)
123 << "type_idx=" << i << " " << 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
Calin Juravle877fd962016-01-05 14:29:29 +0000185class CompilerDriverProfileTest : public CompilerDriverTest {
186 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100187 ProfileCompilationInfo* GetProfileCompilationInfo() override {
Calin Juravle877fd962016-01-05 14:29:29 +0000188 ScopedObjectAccess soa(Thread::Current());
189 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("ProfileTestMultiDex");
190
191 ProfileCompilationInfo info;
192 for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
Mathieu Chartierbbe3a5e2017-06-13 16:36:17 -0700193 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
194 MethodReference(dex_file.get(), 1));
195 profile_info_.AddMethodIndex(ProfileCompilationInfo::MethodHotness::kFlagHot,
196 MethodReference(dex_file.get(), 2));
Calin Juravle877fd962016-01-05 14:29:29 +0000197 }
198 return &profile_info_;
199 }
200
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100201 CompilerFilter::Filter GetCompilerFilter() const override {
Mathieu Chartierd0af56c2017-02-17 12:56:25 -0800202 // Use a profile based filter.
203 return CompilerFilter::kSpeedProfile;
204 }
205
Calin Juravle877fd962016-01-05 14:29:29 +0000206 std::unordered_set<std::string> GetExpectedMethodsForClass(const std::string& clazz) {
207 if (clazz == "Main") {
208 return std::unordered_set<std::string>({
209 "java.lang.String Main.getA()",
210 "java.lang.String Main.getB()"});
211 } else if (clazz == "Second") {
212 return std::unordered_set<std::string>({
213 "java.lang.String Second.getX()",
214 "java.lang.String Second.getY()"});
215 } else {
216 return std::unordered_set<std::string>();
217 }
218 }
219
220 void CheckCompiledMethods(jobject class_loader,
221 const std::string& clazz,
222 const std::unordered_set<std::string>& expected_methods) {
223 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
224 Thread* self = Thread::Current();
225 ScopedObjectAccess soa(self);
226 StackHandleScope<1> hs(self);
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700227 Handle<mirror::ClassLoader> h_loader(
228 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100229 ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
Calin Juravle877fd962016-01-05 14:29:29 +0000230 ASSERT_NE(klass, nullptr);
231
232 const auto pointer_size = class_linker->GetImagePointerSize();
233 size_t number_of_compiled_methods = 0;
234 for (auto& m : klass->GetVirtualMethods(pointer_size)) {
David Sehr709b0702016-10-13 09:12:37 -0700235 std::string name = m.PrettyMethod(true);
Calin Juravle877fd962016-01-05 14:29:29 +0000236 const void* code = m.GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
237 ASSERT_NE(code, nullptr);
238 if (expected_methods.find(name) != expected_methods.end()) {
239 number_of_compiled_methods++;
240 EXPECT_FALSE(class_linker->IsQuickToInterpreterBridge(code));
241 } else {
242 EXPECT_TRUE(class_linker->IsQuickToInterpreterBridge(code));
243 }
244 }
245 EXPECT_EQ(expected_methods.size(), number_of_compiled_methods);
246 }
247
248 private:
249 ProfileCompilationInfo profile_info_;
250};
251
252TEST_F(CompilerDriverProfileTest, ProfileGuidedCompilation) {
Calin Juravle877fd962016-01-05 14:29:29 +0000253 Thread* self = Thread::Current();
254 jobject class_loader;
255 {
256 ScopedObjectAccess soa(self);
257 class_loader = LoadDex("ProfileTestMultiDex");
258 }
259 ASSERT_NE(class_loader, nullptr);
260
261 // Need to enable dex-file writability. Methods rejected to be compiled will run through the
262 // dex-to-dex compiler.
Calin Juravle877fd962016-01-05 14:29:29 +0000263 for (const DexFile* dex_file : GetDexFiles(class_loader)) {
264 ASSERT_TRUE(dex_file->EnableWrite());
265 }
266
Vladimir Marko2afaff72018-11-30 17:01:50 +0000267 CompileAllAndMakeExecutable(class_loader);
Calin Juravle877fd962016-01-05 14:29:29 +0000268
269 std::unordered_set<std::string> m = GetExpectedMethodsForClass("Main");
270 std::unordered_set<std::string> s = GetExpectedMethodsForClass("Second");
271 CheckCompiledMethods(class_loader, "LMain;", m);
272 CheckCompiledMethods(class_loader, "LSecond;", s);
273}
274
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100275// Test that a verify only compiler filter updates the CompiledClass map,
276// which will be used for OatClass.
277class CompilerDriverVerifyTest : public CompilerDriverTest {
278 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100279 CompilerFilter::Filter GetCompilerFilter() const override {
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100280 return CompilerFilter::kVerify;
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100281 }
282
283 void CheckVerifiedClass(jobject class_loader, const std::string& clazz) const {
284 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
285 Thread* self = Thread::Current();
286 ScopedObjectAccess soa(self);
287 StackHandleScope<1> hs(self);
288 Handle<mirror::ClassLoader> h_loader(
289 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100290 ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader);
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100291 ASSERT_NE(klass, nullptr);
292 EXPECT_TRUE(klass->IsVerified());
293
Vladimir Marko2c64a832018-01-04 11:31:56 +0000294 ClassStatus status;
Andreas Gampebb846102017-05-11 21:03:35 -0700295 bool found = compiler_driver_->GetCompiledClass(
296 ClassReference(&klass->GetDexFile(), klass->GetDexTypeIndex().index_), &status);
297 ASSERT_TRUE(found);
Vladimir Marko2c64a832018-01-04 11:31:56 +0000298 EXPECT_EQ(status, ClassStatus::kVerified);
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100299 }
300};
301
302TEST_F(CompilerDriverVerifyTest, VerifyCompilation) {
303 Thread* self = Thread::Current();
304 jobject class_loader;
305 {
306 ScopedObjectAccess soa(self);
307 class_loader = LoadDex("ProfileTestMultiDex");
308 }
309 ASSERT_NE(class_loader, nullptr);
310
Vladimir Marko2afaff72018-11-30 17:01:50 +0000311 CompileAllAndMakeExecutable(class_loader);
Nicolas Geoffrayc7da1d62017-04-19 09:36:24 +0100312
313 CheckVerifiedClass(class_loader, "LMain;");
314 CheckVerifiedClass(class_loader, "LSecond;");
315}
316
Vladimir Marko2c64a832018-01-04 11:31:56 +0000317// Test that a class of status ClassStatus::kRetryVerificationAtRuntime is indeed
318// recorded that way in the driver.
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700319TEST_F(CompilerDriverVerifyTest, RetryVerifcationStatusCheckVerified) {
Jeff Haof1aa2652017-08-03 17:09:33 -0700320 Thread* const self = Thread::Current();
321 jobject class_loader;
322 std::vector<const DexFile*> dex_files;
323 const DexFile* dex_file = nullptr;
324 {
325 ScopedObjectAccess soa(self);
326 class_loader = LoadDex("ProfileTestMultiDex");
327 ASSERT_NE(class_loader, nullptr);
328 dex_files = GetDexFiles(class_loader);
329 ASSERT_GT(dex_files.size(), 0u);
330 dex_file = dex_files.front();
331 }
Vladimir Marko213ee2d2018-06-22 11:56:34 +0100332 SetDexFilesForOatFile(dex_files);
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700333 callbacks_->SetDoesClassUnloading(true, compiler_driver_.get());
Jeff Haof1aa2652017-08-03 17:09:33 -0700334 ClassReference ref(dex_file, 0u);
335 // Test that the status is read from the compiler driver as expected.
Vladimir Marko2c64a832018-01-04 11:31:56 +0000336 static_assert(enum_cast<size_t>(ClassStatus::kLast) < std::numeric_limits<size_t>::max(),
337 "Make sure incrementing the class status does not overflow.");
338 for (size_t i = enum_cast<size_t>(ClassStatus::kRetryVerificationAtRuntime);
339 i <= enum_cast<size_t>(ClassStatus::kLast);
340 ++i) {
341 const ClassStatus expected_status = enum_cast<ClassStatus>(i);
Jeff Haof1aa2652017-08-03 17:09:33 -0700342 // Skip unsupported status that are not supposed to be ever recorded.
Vladimir Marko2c64a832018-01-04 11:31:56 +0000343 if (expected_status == ClassStatus::kVerifyingAtRuntime ||
344 expected_status == ClassStatus::kInitializing) {
Jeff Haof1aa2652017-08-03 17:09:33 -0700345 continue;
346 }
347 compiler_driver_->RecordClassStatus(ref, expected_status);
Vladimir Marko2c64a832018-01-04 11:31:56 +0000348 ClassStatus status = {};
Jeff Haof1aa2652017-08-03 17:09:33 -0700349 ASSERT_TRUE(compiler_driver_->GetCompiledClass(ref, &status));
350 EXPECT_EQ(status, expected_status);
351 }
352}
353
Brian Carlstrom7940e442013-07-12 13:46:57 -0700354// TODO: need check-cast test (when stub complete & we can throw/catch
355
356} // namespace art