David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "verifier_deps.h" |
| 18 | |
| 19 | #include "class_linker.h" |
| 20 | #include "common_runtime_test.h" |
| 21 | #include "compiler_callbacks.h" |
| 22 | #include "dex_file.h" |
| 23 | #include "handle_scope-inl.h" |
| 24 | #include "method_verifier-inl.h" |
| 25 | #include "mirror/class_loader.h" |
| 26 | #include "runtime.h" |
| 27 | #include "thread.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 28 | #include "scoped_thread_state_change-inl.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | namespace verifier { |
| 32 | |
| 33 | class VerifierDepsCompilerCallbacks : public CompilerCallbacks { |
| 34 | public: |
| 35 | explicit VerifierDepsCompilerCallbacks() |
| 36 | : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp), |
| 37 | deps_(nullptr) {} |
| 38 | |
| 39 | void MethodVerified(verifier::MethodVerifier* verifier ATTRIBUTE_UNUSED) OVERRIDE {} |
| 40 | void ClassRejected(ClassReference ref ATTRIBUTE_UNUSED) OVERRIDE {} |
| 41 | bool IsRelocationPossible() OVERRIDE { return false; } |
| 42 | |
| 43 | verifier::VerifierDeps* GetVerifierDeps() const OVERRIDE { return deps_; } |
| 44 | void SetVerifierDeps(verifier::VerifierDeps* deps) { deps_ = deps; } |
| 45 | |
| 46 | private: |
| 47 | verifier::VerifierDeps* deps_; |
| 48 | }; |
| 49 | |
| 50 | class VerifierDepsTest : public CommonRuntimeTest { |
| 51 | public: |
| 52 | void SetUpRuntimeOptions(RuntimeOptions* options) { |
| 53 | CommonRuntimeTest::SetUpRuntimeOptions(options); |
| 54 | callbacks_.reset(new VerifierDepsCompilerCallbacks()); |
| 55 | } |
| 56 | |
| 57 | mirror::Class* FindClassByName(const std::string& name, ScopedObjectAccess* soa) |
| 58 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 59 | StackHandleScope<1> hs(Thread::Current()); |
| 60 | Handle<mirror::ClassLoader> class_loader_handle( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 61 | hs.NewHandle(soa->Decode<mirror::ClassLoader>(class_loader_))); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 62 | mirror::Class* klass = class_linker_->FindClass(Thread::Current(), |
| 63 | name.c_str(), |
| 64 | class_loader_handle); |
| 65 | if (klass == nullptr) { |
| 66 | DCHECK(Thread::Current()->IsExceptionPending()); |
| 67 | Thread::Current()->ClearException(); |
| 68 | } |
| 69 | return klass; |
| 70 | } |
| 71 | |
| 72 | void SetVerifierDeps(const std::vector<const DexFile*>& dex_files) { |
| 73 | verifier_deps_.reset(new verifier::VerifierDeps(dex_files)); |
| 74 | VerifierDepsCompilerCallbacks* callbacks = |
| 75 | reinterpret_cast<VerifierDepsCompilerCallbacks*>(callbacks_.get()); |
| 76 | callbacks->SetVerifierDeps(verifier_deps_.get()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void LoadDexFile(ScopedObjectAccess* soa) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 80 | class_loader_ = LoadDex("VerifierDeps"); |
| 81 | std::vector<const DexFile*> dex_files = GetDexFiles(class_loader_); |
| 82 | CHECK_EQ(dex_files.size(), 1u); |
| 83 | dex_file_ = dex_files.front(); |
| 84 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 85 | SetVerifierDeps(dex_files); |
| 86 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 87 | ObjPtr<mirror::ClassLoader> loader = soa->Decode<mirror::ClassLoader>(class_loader_); |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame^] | 88 | class_linker_->RegisterDexFile(*dex_file_, loader.Ptr()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 89 | |
| 90 | klass_Main_ = FindClassByName("LMain;", soa); |
| 91 | CHECK(klass_Main_ != nullptr); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | bool VerifyMethod(const std::string& method_name) { |
| 95 | ScopedObjectAccess soa(Thread::Current()); |
| 96 | LoadDexFile(&soa); |
| 97 | |
| 98 | StackHandleScope<2> hs(Thread::Current()); |
| 99 | Handle<mirror::ClassLoader> class_loader_handle( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 100 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 101 | Handle<mirror::DexCache> dex_cache_handle(hs.NewHandle(klass_Main_->GetDexCache())); |
| 102 | |
| 103 | const DexFile::ClassDef* class_def = klass_Main_->GetClassDef(); |
| 104 | const uint8_t* class_data = dex_file_->GetClassData(*class_def); |
| 105 | CHECK(class_data != nullptr); |
| 106 | |
| 107 | ClassDataItemIterator it(*dex_file_, class_data); |
| 108 | while (it.HasNextStaticField() || it.HasNextInstanceField()) { |
| 109 | it.Next(); |
| 110 | } |
| 111 | |
| 112 | ArtMethod* method = nullptr; |
| 113 | while (it.HasNextDirectMethod()) { |
| 114 | ArtMethod* resolved_method = class_linker_->ResolveMethod<ClassLinker::kNoICCECheckForCache>( |
| 115 | *dex_file_, |
| 116 | it.GetMemberIndex(), |
| 117 | dex_cache_handle, |
| 118 | class_loader_handle, |
| 119 | nullptr, |
| 120 | it.GetMethodInvokeType(*class_def)); |
| 121 | CHECK(resolved_method != nullptr); |
| 122 | if (method_name == resolved_method->GetName()) { |
| 123 | method = resolved_method; |
| 124 | break; |
| 125 | } |
| 126 | it.Next(); |
| 127 | } |
| 128 | CHECK(method != nullptr); |
| 129 | |
| 130 | MethodVerifier verifier(Thread::Current(), |
| 131 | dex_file_, |
| 132 | dex_cache_handle, |
| 133 | class_loader_handle, |
| 134 | *class_def, |
| 135 | it.GetMethodCodeItem(), |
| 136 | it.GetMemberIndex(), |
| 137 | method, |
| 138 | it.GetMethodAccessFlags(), |
| 139 | true /* can_load_classes */, |
| 140 | true /* allow_soft_failures */, |
| 141 | true /* need_precise_constants */, |
| 142 | false /* verify to dump */, |
| 143 | true /* allow_thread_suspension */); |
| 144 | verifier.Verify(); |
| 145 | return !verifier.HasFailures(); |
| 146 | } |
| 147 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 148 | void VerifyDexFile() { |
| 149 | std::string error_msg; |
| 150 | ScopedObjectAccess soa(Thread::Current()); |
| 151 | |
| 152 | LoadDexFile(&soa); |
| 153 | SetVerifierDeps({ dex_file_ }); |
| 154 | |
| 155 | for (size_t i = 0; i < dex_file_->NumClassDefs(); i++) { |
| 156 | const char* descriptor = dex_file_->GetClassDescriptor(dex_file_->GetClassDef(i)); |
| 157 | mirror::Class* klass = FindClassByName(descriptor, &soa); |
| 158 | if (klass != nullptr) { |
| 159 | MethodVerifier::VerifyClass(Thread::Current(), |
| 160 | klass, |
| 161 | nullptr, |
| 162 | true, |
| 163 | HardFailLogMode::kLogWarning, |
| 164 | &error_msg); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 169 | bool TestAssignabilityRecording(const std::string& dst, |
| 170 | const std::string& src, |
| 171 | bool is_strict, |
| 172 | bool is_assignable) { |
| 173 | ScopedObjectAccess soa(Thread::Current()); |
| 174 | LoadDexFile(&soa); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 175 | mirror::Class* klass_dst = FindClassByName(dst, &soa); |
| 176 | DCHECK(klass_dst != nullptr); |
| 177 | mirror::Class* klass_src = FindClassByName(src, &soa); |
| 178 | DCHECK(klass_src != nullptr); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 179 | verifier_deps_->AddAssignability(*dex_file_, |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 180 | klass_dst, |
| 181 | klass_src, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 182 | is_strict, |
| 183 | is_assignable); |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | // Iterates over all assignability records and tries to find an entry which |
| 188 | // matches the expected destination/source pair. |
| 189 | bool HasAssignable(const std::string& expected_destination, |
| 190 | const std::string& expected_source, |
| 191 | bool expected_is_assignable) { |
| 192 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 193 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 194 | const DexFile& dex_file = *dex_dep.first; |
| 195 | auto& storage = expected_is_assignable ? dex_dep.second->assignable_types_ |
| 196 | : dex_dep.second->unassignable_types_; |
| 197 | for (auto& entry : storage) { |
| 198 | std::string actual_destination = |
| 199 | verifier_deps_->GetStringFromId(dex_file, entry.GetDestination()); |
| 200 | std::string actual_source = verifier_deps_->GetStringFromId(dex_file, entry.GetSource()); |
| 201 | if ((expected_destination == actual_destination) && (expected_source == actual_source)) { |
| 202 | return true; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | // Iterates over all class resolution records, finds an entry which matches |
| 210 | // the given class descriptor and tests its properties. |
| 211 | bool HasClass(const std::string& expected_klass, |
| 212 | bool expected_resolved, |
| 213 | const std::string& expected_access_flags = "") { |
| 214 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 215 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 216 | for (auto& entry : dex_dep.second->classes_) { |
| 217 | if (expected_resolved != entry.IsResolved()) { |
| 218 | continue; |
| 219 | } |
| 220 | |
| 221 | std::string actual_klass = dex_dep.first->StringByTypeIdx(entry.GetDexTypeIndex()); |
| 222 | if (expected_klass != actual_klass) { |
| 223 | continue; |
| 224 | } |
| 225 | |
| 226 | if (expected_resolved) { |
| 227 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 228 | // a space after the modifiers. Add it to the expected access flags. |
| 229 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 230 | if (expected_access_flags + " " != actual_access_flags) { |
| 231 | continue; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return true; |
| 236 | } |
| 237 | } |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | // Iterates over all field resolution records, finds an entry which matches |
| 242 | // the given field class+name+type and tests its properties. |
| 243 | bool HasField(const std::string& expected_klass, |
| 244 | const std::string& expected_name, |
| 245 | const std::string& expected_type, |
| 246 | bool expected_resolved, |
| 247 | const std::string& expected_access_flags = "", |
| 248 | const std::string& expected_decl_klass = "") { |
| 249 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 250 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 251 | for (auto& entry : dex_dep.second->fields_) { |
| 252 | if (expected_resolved != entry.IsResolved()) { |
| 253 | continue; |
| 254 | } |
| 255 | |
| 256 | const DexFile::FieldId& field_id = dex_dep.first->GetFieldId(entry.GetDexFieldIndex()); |
| 257 | |
| 258 | std::string actual_klass = dex_dep.first->StringByTypeIdx(field_id.class_idx_); |
| 259 | if (expected_klass != actual_klass) { |
| 260 | continue; |
| 261 | } |
| 262 | |
| 263 | std::string actual_name = dex_dep.first->StringDataByIdx(field_id.name_idx_); |
| 264 | if (expected_name != actual_name) { |
| 265 | continue; |
| 266 | } |
| 267 | |
| 268 | std::string actual_type = dex_dep.first->StringByTypeIdx(field_id.type_idx_); |
| 269 | if (expected_type != actual_type) { |
| 270 | continue; |
| 271 | } |
| 272 | |
| 273 | if (expected_resolved) { |
| 274 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 275 | // a space after the modifiers. Add it to the expected access flags. |
| 276 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 277 | if (expected_access_flags + " " != actual_access_flags) { |
| 278 | continue; |
| 279 | } |
| 280 | |
| 281 | std::string actual_decl_klass = verifier_deps_->GetStringFromId( |
| 282 | *dex_dep.first, entry.GetDeclaringClassIndex()); |
| 283 | if (expected_decl_klass != actual_decl_klass) { |
| 284 | continue; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return true; |
| 289 | } |
| 290 | } |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | // Iterates over all method resolution records, finds an entry which matches |
| 295 | // the given field kind+class+name+signature and tests its properties. |
| 296 | bool HasMethod(const std::string& expected_kind, |
| 297 | const std::string& expected_klass, |
| 298 | const std::string& expected_name, |
| 299 | const std::string& expected_signature, |
| 300 | bool expected_resolved, |
| 301 | const std::string& expected_access_flags = "", |
| 302 | const std::string& expected_decl_klass = "") { |
| 303 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 304 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 305 | auto& storage = (expected_kind == "direct") ? dex_dep.second->direct_methods_ |
| 306 | : (expected_kind == "virtual") ? dex_dep.second->virtual_methods_ |
| 307 | : dex_dep.second->interface_methods_; |
| 308 | for (auto& entry : storage) { |
| 309 | if (expected_resolved != entry.IsResolved()) { |
| 310 | continue; |
| 311 | } |
| 312 | |
| 313 | const DexFile::MethodId& method_id = dex_dep.first->GetMethodId(entry.GetDexMethodIndex()); |
| 314 | |
| 315 | std::string actual_klass = dex_dep.first->StringByTypeIdx(method_id.class_idx_); |
| 316 | if (expected_klass != actual_klass) { |
| 317 | continue; |
| 318 | } |
| 319 | |
| 320 | std::string actual_name = dex_dep.first->StringDataByIdx(method_id.name_idx_); |
| 321 | if (expected_name != actual_name) { |
| 322 | continue; |
| 323 | } |
| 324 | |
| 325 | std::string actual_signature = dex_dep.first->GetMethodSignature(method_id).ToString(); |
| 326 | if (expected_signature != actual_signature) { |
| 327 | continue; |
| 328 | } |
| 329 | |
| 330 | if (expected_resolved) { |
| 331 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 332 | // a space after the modifiers. Add it to the expected access flags. |
| 333 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 334 | if (expected_access_flags + " " != actual_access_flags) { |
| 335 | continue; |
| 336 | } |
| 337 | |
| 338 | std::string actual_decl_klass = verifier_deps_->GetStringFromId( |
| 339 | *dex_dep.first, entry.GetDeclaringClassIndex()); |
| 340 | if (expected_decl_klass != actual_decl_klass) { |
| 341 | continue; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | } |
| 348 | return false; |
| 349 | } |
| 350 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 351 | size_t NumberOfCompiledDexFiles() { |
| 352 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 353 | return verifier_deps_->dex_deps_.size(); |
| 354 | } |
| 355 | |
| 356 | size_t HasEachKindOfRecord() { |
| 357 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 358 | |
| 359 | bool has_strings = false; |
| 360 | bool has_assignability = false; |
| 361 | bool has_classes = false; |
| 362 | bool has_fields = false; |
| 363 | bool has_methods = false; |
| 364 | |
| 365 | for (auto& entry : verifier_deps_->dex_deps_) { |
| 366 | has_strings |= !entry.second->strings_.empty(); |
| 367 | has_assignability |= !entry.second->assignable_types_.empty(); |
| 368 | has_assignability |= !entry.second->unassignable_types_.empty(); |
| 369 | has_classes |= !entry.second->classes_.empty(); |
| 370 | has_fields |= !entry.second->fields_.empty(); |
| 371 | has_methods |= !entry.second->direct_methods_.empty(); |
| 372 | has_methods |= !entry.second->virtual_methods_.empty(); |
| 373 | has_methods |= !entry.second->interface_methods_.empty(); |
| 374 | } |
| 375 | |
| 376 | return has_strings && has_assignability && has_classes && has_fields && has_methods; |
| 377 | } |
| 378 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 379 | std::unique_ptr<verifier::VerifierDeps> verifier_deps_; |
| 380 | const DexFile* dex_file_; |
| 381 | jobject class_loader_; |
| 382 | mirror::Class* klass_Main_; |
| 383 | }; |
| 384 | |
| 385 | TEST_F(VerifierDepsTest, StringToId) { |
| 386 | ScopedObjectAccess soa(Thread::Current()); |
| 387 | LoadDexFile(&soa); |
| 388 | |
| 389 | MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_); |
| 390 | |
| 391 | uint32_t id_Main1 = verifier_deps_->GetIdFromString(*dex_file_, "LMain;"); |
| 392 | ASSERT_LT(id_Main1, dex_file_->NumStringIds()); |
| 393 | ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*dex_file_, id_Main1)); |
| 394 | |
| 395 | uint32_t id_Main2 = verifier_deps_->GetIdFromString(*dex_file_, "LMain;"); |
| 396 | ASSERT_LT(id_Main2, dex_file_->NumStringIds()); |
| 397 | ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*dex_file_, id_Main2)); |
| 398 | |
| 399 | uint32_t id_Lorem1 = verifier_deps_->GetIdFromString(*dex_file_, "Lorem ipsum"); |
| 400 | ASSERT_GE(id_Lorem1, dex_file_->NumStringIds()); |
| 401 | ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*dex_file_, id_Lorem1)); |
| 402 | |
| 403 | uint32_t id_Lorem2 = verifier_deps_->GetIdFromString(*dex_file_, "Lorem ipsum"); |
| 404 | ASSERT_GE(id_Lorem2, dex_file_->NumStringIds()); |
| 405 | ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*dex_file_, id_Lorem2)); |
| 406 | |
| 407 | ASSERT_EQ(id_Main1, id_Main2); |
| 408 | ASSERT_EQ(id_Lorem1, id_Lorem2); |
| 409 | ASSERT_NE(id_Main1, id_Lorem1); |
| 410 | } |
| 411 | |
| 412 | TEST_F(VerifierDepsTest, Assignable_BothInBoot) { |
| 413 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;", |
| 414 | /* src */ "Ljava/util/SimpleTimeZone;", |
| 415 | /* is_strict */ true, |
| 416 | /* is_assignable */ true)); |
| 417 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 418 | } |
| 419 | |
| 420 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot1) { |
| 421 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/net/Socket;", |
| 422 | /* src */ "LMySSLSocket;", |
| 423 | /* is_strict */ true, |
| 424 | /* is_assignable */ true)); |
| 425 | ASSERT_TRUE(HasAssignable("Ljava/net/Socket;", "LMySSLSocket;", true)); |
| 426 | } |
| 427 | |
| 428 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot2) { |
| 429 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;", |
| 430 | /* src */ "LMySimpleTimeZone;", |
| 431 | /* is_strict */ true, |
| 432 | /* is_assignable */ true)); |
| 433 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "LMySimpleTimeZone;", true)); |
| 434 | } |
| 435 | |
| 436 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot3) { |
| 437 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/Collection;", |
| 438 | /* src */ "LMyThreadSet;", |
| 439 | /* is_strict */ true, |
| 440 | /* is_assignable */ true)); |
| 441 | ASSERT_TRUE(HasAssignable("Ljava/util/Collection;", "LMyThreadSet;", true)); |
| 442 | } |
| 443 | |
| 444 | TEST_F(VerifierDepsTest, Assignable_BothArrays_Resolved) { |
| 445 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[[Ljava/util/TimeZone;", |
| 446 | /* src */ "[[Ljava/util/SimpleTimeZone;", |
| 447 | /* is_strict */ true, |
| 448 | /* is_assignable */ true)); |
| 449 | // If the component types of both arrays are resolved, we optimize the list of |
| 450 | // dependencies by recording a dependency on the component types. |
| 451 | ASSERT_FALSE(HasAssignable("[[Ljava/util/TimeZone;", "[[Ljava/util/SimpleTimeZone;", true)); |
| 452 | ASSERT_FALSE(HasAssignable("[Ljava/util/TimeZone;", "[Ljava/util/SimpleTimeZone;", true)); |
| 453 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 454 | } |
| 455 | |
| 456 | TEST_F(VerifierDepsTest, Assignable_BothArrays_Erroneous) { |
| 457 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[[Ljava/util/TimeZone;", |
| 458 | /* src */ "[[LMyErroneousTimeZone;", |
| 459 | /* is_strict */ true, |
| 460 | /* is_assignable */ true)); |
| 461 | // If the component type of an array is erroneous, we record the dependency on |
| 462 | // the array type. |
| 463 | ASSERT_FALSE(HasAssignable("[[Ljava/util/TimeZone;", "[[LMyErroneousTimeZone;", true)); |
| 464 | ASSERT_TRUE(HasAssignable("[Ljava/util/TimeZone;", "[LMyErroneousTimeZone;", true)); |
| 465 | ASSERT_FALSE(HasAssignable("Ljava/util/TimeZone;", "LMyErroneousTimeZone;", true)); |
| 466 | } |
| 467 | |
| 468 | // We test that VerifierDeps does not try to optimize by storing assignability |
| 469 | // of the component types. This is due to the fact that the component type may |
| 470 | // be an erroneous class, even though the array type has resolved status. |
| 471 | |
| 472 | TEST_F(VerifierDepsTest, Assignable_ArrayToInterface1) { |
| 473 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/io/Serializable;", |
| 474 | /* src */ "[Ljava/util/TimeZone;", |
| 475 | /* is_strict */ true, |
| 476 | /* is_assignable */ true)); |
| 477 | ASSERT_TRUE(HasAssignable("Ljava/io/Serializable;", "[Ljava/util/TimeZone;", true)); |
| 478 | } |
| 479 | |
| 480 | TEST_F(VerifierDepsTest, Assignable_ArrayToInterface2) { |
| 481 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/io/Serializable;", |
| 482 | /* src */ "[LMyThreadSet;", |
| 483 | /* is_strict */ true, |
| 484 | /* is_assignable */ true)); |
| 485 | ASSERT_TRUE(HasAssignable("Ljava/io/Serializable;", "[LMyThreadSet;", true)); |
| 486 | } |
| 487 | |
| 488 | TEST_F(VerifierDepsTest, NotAssignable_BothInBoot) { |
| 489 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 490 | /* src */ "Ljava/util/SimpleTimeZone;", |
| 491 | /* is_strict */ true, |
| 492 | /* is_assignable */ false)); |
| 493 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false)); |
| 494 | } |
| 495 | |
| 496 | TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot1) { |
| 497 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 498 | /* src */ "LMySSLSocket;", |
| 499 | /* is_strict */ true, |
| 500 | /* is_assignable */ false)); |
| 501 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySSLSocket;", false)); |
| 502 | } |
| 503 | |
| 504 | TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot2) { |
| 505 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 506 | /* src */ "LMySimpleTimeZone;", |
| 507 | /* is_strict */ true, |
| 508 | /* is_assignable */ false)); |
| 509 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySimpleTimeZone;", false)); |
| 510 | } |
| 511 | |
| 512 | TEST_F(VerifierDepsTest, NotAssignable_BothArrays) { |
| 513 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[Ljava/lang/Exception;", |
| 514 | /* src */ "[Ljava/util/SimpleTimeZone;", |
| 515 | /* is_strict */ true, |
| 516 | /* is_assignable */ false)); |
| 517 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false)); |
| 518 | } |
| 519 | |
| 520 | TEST_F(VerifierDepsTest, ArgumentType_ResolvedClass) { |
| 521 | ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedClass")); |
| 522 | ASSERT_TRUE(HasClass("Ljava/lang/Thread;", true, "public")); |
| 523 | } |
| 524 | |
| 525 | TEST_F(VerifierDepsTest, ArgumentType_ResolvedReferenceArray) { |
| 526 | ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedReferenceArray")); |
| 527 | ASSERT_TRUE(HasClass("[Ljava/lang/Thread;", true, "public final abstract")); |
| 528 | } |
| 529 | |
| 530 | TEST_F(VerifierDepsTest, ArgumentType_ResolvedPrimitiveArray) { |
| 531 | ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedPrimitiveArray")); |
| 532 | ASSERT_TRUE(HasClass("[B", true, "public final abstract")); |
| 533 | } |
| 534 | |
| 535 | TEST_F(VerifierDepsTest, ArgumentType_UnresolvedClass) { |
| 536 | ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedClass")); |
| 537 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 538 | } |
| 539 | |
| 540 | TEST_F(VerifierDepsTest, ArgumentType_UnresolvedSuper) { |
| 541 | ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedSuper")); |
| 542 | ASSERT_TRUE(HasClass("LMySetWithUnresolvedSuper;", false)); |
| 543 | } |
| 544 | |
| 545 | TEST_F(VerifierDepsTest, ReturnType_Reference) { |
| 546 | ASSERT_TRUE(VerifyMethod("ReturnType_Reference")); |
| 547 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true)); |
| 548 | } |
| 549 | |
| 550 | TEST_F(VerifierDepsTest, ReturnType_Array) { |
| 551 | ASSERT_FALSE(VerifyMethod("ReturnType_Array")); |
| 552 | ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "Ljava/lang/IllegalStateException;", false)); |
| 553 | } |
| 554 | |
| 555 | TEST_F(VerifierDepsTest, InvokeArgumentType) { |
| 556 | ASSERT_TRUE(VerifyMethod("InvokeArgumentType")); |
| 557 | ASSERT_TRUE(HasClass("Ljava/text/SimpleDateFormat;", true, "public")); |
| 558 | ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public")); |
| 559 | ASSERT_TRUE(HasMethod("virtual", |
| 560 | "Ljava/text/SimpleDateFormat;", |
| 561 | "setTimeZone", |
| 562 | "(Ljava/util/TimeZone;)V", |
| 563 | true, |
| 564 | "public", |
| 565 | "Ljava/text/DateFormat;")); |
| 566 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 567 | } |
| 568 | |
| 569 | TEST_F(VerifierDepsTest, MergeTypes_RegisterLines) { |
| 570 | ASSERT_TRUE(VerifyMethod("MergeTypes_RegisterLines")); |
| 571 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySocketTimeoutException;", true)); |
| 572 | ASSERT_TRUE(HasAssignable( |
| 573 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 574 | } |
| 575 | |
| 576 | TEST_F(VerifierDepsTest, MergeTypes_IfInstanceOf) { |
| 577 | ASSERT_TRUE(VerifyMethod("MergeTypes_IfInstanceOf")); |
| 578 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true)); |
| 579 | ASSERT_TRUE(HasAssignable( |
| 580 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 581 | ASSERT_TRUE(HasAssignable("Ljava/net/SocketTimeoutException;", "Ljava/lang/Exception;", false)); |
| 582 | } |
| 583 | |
| 584 | TEST_F(VerifierDepsTest, MergeTypes_Unresolved) { |
| 585 | ASSERT_TRUE(VerifyMethod("MergeTypes_Unresolved")); |
| 586 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true)); |
| 587 | ASSERT_TRUE(HasAssignable( |
| 588 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 589 | } |
| 590 | |
| 591 | TEST_F(VerifierDepsTest, ConstClass_Resolved) { |
| 592 | ASSERT_TRUE(VerifyMethod("ConstClass_Resolved")); |
| 593 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 594 | } |
| 595 | |
| 596 | TEST_F(VerifierDepsTest, ConstClass_Unresolved) { |
| 597 | ASSERT_TRUE(VerifyMethod("ConstClass_Unresolved")); |
| 598 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 599 | } |
| 600 | |
| 601 | TEST_F(VerifierDepsTest, CheckCast_Resolved) { |
| 602 | ASSERT_TRUE(VerifyMethod("CheckCast_Resolved")); |
| 603 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 604 | } |
| 605 | |
| 606 | TEST_F(VerifierDepsTest, CheckCast_Unresolved) { |
| 607 | ASSERT_TRUE(VerifyMethod("CheckCast_Unresolved")); |
| 608 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 609 | } |
| 610 | |
| 611 | TEST_F(VerifierDepsTest, InstanceOf_Resolved) { |
| 612 | ASSERT_TRUE(VerifyMethod("InstanceOf_Resolved")); |
| 613 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 614 | } |
| 615 | |
| 616 | TEST_F(VerifierDepsTest, InstanceOf_Unresolved) { |
| 617 | ASSERT_TRUE(VerifyMethod("InstanceOf_Unresolved")); |
| 618 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 619 | } |
| 620 | |
| 621 | TEST_F(VerifierDepsTest, NewInstance_Resolved) { |
| 622 | ASSERT_TRUE(VerifyMethod("NewInstance_Resolved")); |
| 623 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 624 | } |
| 625 | |
| 626 | TEST_F(VerifierDepsTest, NewInstance_Unresolved) { |
| 627 | ASSERT_TRUE(VerifyMethod("NewInstance_Unresolved")); |
| 628 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 629 | } |
| 630 | |
| 631 | TEST_F(VerifierDepsTest, NewArray_Resolved) { |
| 632 | ASSERT_TRUE(VerifyMethod("NewArray_Resolved")); |
| 633 | ASSERT_TRUE(HasClass("[Ljava/lang/IllegalStateException;", true, "public final abstract")); |
| 634 | } |
| 635 | |
| 636 | TEST_F(VerifierDepsTest, NewArray_Unresolved) { |
| 637 | ASSERT_TRUE(VerifyMethod("NewArray_Unresolved")); |
| 638 | ASSERT_TRUE(HasClass("[LUnresolvedClass;", false)); |
| 639 | } |
| 640 | |
| 641 | TEST_F(VerifierDepsTest, Throw) { |
| 642 | ASSERT_TRUE(VerifyMethod("Throw")); |
| 643 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true)); |
| 644 | } |
| 645 | |
| 646 | TEST_F(VerifierDepsTest, MoveException_Resolved) { |
| 647 | ASSERT_TRUE(VerifyMethod("MoveException_Resolved")); |
| 648 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 649 | ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public")); |
| 650 | ASSERT_TRUE(HasClass("Ljava/util/zip/ZipException;", true, "public")); |
| 651 | |
| 652 | // Testing that all exception types are assignable to Throwable. |
| 653 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/InterruptedIOException;", true)); |
| 654 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/net/SocketTimeoutException;", true)); |
| 655 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/util/zip/ZipException;", true)); |
| 656 | |
| 657 | // Testing that the merge type is assignable to Throwable. |
| 658 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/IOException;", true)); |
| 659 | |
| 660 | // Merging of exception types. |
| 661 | ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/io/InterruptedIOException;", true)); |
| 662 | ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/util/zip/ZipException;", true)); |
| 663 | ASSERT_TRUE(HasAssignable( |
| 664 | "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true)); |
| 665 | } |
| 666 | |
| 667 | TEST_F(VerifierDepsTest, MoveException_Unresolved) { |
| 668 | ASSERT_FALSE(VerifyMethod("MoveException_Unresolved")); |
| 669 | ASSERT_TRUE(HasClass("LUnresolvedException;", false)); |
| 670 | } |
| 671 | |
| 672 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInReferenced) { |
| 673 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInReferenced")); |
| 674 | ASSERT_TRUE(HasClass("Ljava/lang/System;", true, "public final")); |
| 675 | ASSERT_TRUE(HasField("Ljava/lang/System;", |
| 676 | "out", |
| 677 | "Ljava/io/PrintStream;", |
| 678 | true, |
| 679 | "public final static", |
| 680 | "Ljava/lang/System;")); |
| 681 | } |
| 682 | |
| 683 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass1) { |
| 684 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass1")); |
| 685 | ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public")); |
| 686 | ASSERT_TRUE(HasField( |
| 687 | "Ljava/util/SimpleTimeZone;", "LONG", "I", true, "public final static", "Ljava/util/TimeZone;")); |
| 688 | } |
| 689 | |
| 690 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass2) { |
| 691 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass2")); |
| 692 | ASSERT_TRUE(HasField( |
| 693 | "LMySimpleTimeZone;", "SHORT", "I", true, "public final static", "Ljava/util/TimeZone;")); |
| 694 | } |
| 695 | |
| 696 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface1) { |
| 697 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface1")); |
| 698 | ASSERT_TRUE(HasClass("Ljavax/xml/transform/dom/DOMResult;", true, "public")); |
| 699 | ASSERT_TRUE(HasField("Ljavax/xml/transform/dom/DOMResult;", |
| 700 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 701 | "Ljava/lang/String;", |
| 702 | true, |
| 703 | "public final static", |
| 704 | "Ljavax/xml/transform/Result;")); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface2) { |
| 708 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface2")); |
| 709 | ASSERT_TRUE(HasField("LMyDOMResult;", |
| 710 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 711 | "Ljava/lang/String;", |
| 712 | true, |
| 713 | "public final static", |
| 714 | "Ljavax/xml/transform/Result;")); |
| 715 | } |
| 716 | |
| 717 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface3) { |
| 718 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface3")); |
| 719 | ASSERT_TRUE(HasField("LMyResult;", |
| 720 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 721 | "Ljava/lang/String;", |
| 722 | true, |
| 723 | "public final static", |
| 724 | "Ljavax/xml/transform/Result;")); |
| 725 | } |
| 726 | |
| 727 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface4) { |
| 728 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface4")); |
| 729 | ASSERT_TRUE(HasField("LMyDocument;", |
| 730 | "ELEMENT_NODE", |
| 731 | "S", |
| 732 | true, |
| 733 | "public final static", |
| 734 | "Lorg/w3c/dom/Node;")); |
| 735 | } |
| 736 | |
| 737 | TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInBoot) { |
| 738 | ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInBoot")); |
| 739 | ASSERT_TRUE(HasClass("Ljava/util/TimeZone;", true, "public abstract")); |
| 740 | ASSERT_TRUE(HasField("Ljava/util/TimeZone;", "x", "I", false)); |
| 741 | } |
| 742 | |
| 743 | TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInDex) { |
| 744 | ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInDex")); |
| 745 | ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false)); |
| 746 | } |
| 747 | |
| 748 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInReferenced) { |
| 749 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInReferenced")); |
| 750 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 751 | ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;", |
| 752 | "bytesTransferred", |
| 753 | "I", |
| 754 | true, |
| 755 | "public", |
| 756 | "Ljava/io/InterruptedIOException;")); |
| 757 | ASSERT_TRUE(HasAssignable( |
| 758 | "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true)); |
| 759 | } |
| 760 | |
| 761 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass1) { |
| 762 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass1")); |
| 763 | ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public")); |
| 764 | ASSERT_TRUE(HasField("Ljava/net/SocketTimeoutException;", |
| 765 | "bytesTransferred", |
| 766 | "I", |
| 767 | true, |
| 768 | "public", |
| 769 | "Ljava/io/InterruptedIOException;")); |
| 770 | ASSERT_TRUE(HasAssignable( |
| 771 | "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true)); |
| 772 | } |
| 773 | |
| 774 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass2) { |
| 775 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass2")); |
| 776 | ASSERT_TRUE(HasField("LMySocketTimeoutException;", |
| 777 | "bytesTransferred", |
| 778 | "I", |
| 779 | true, |
| 780 | "public", |
| 781 | "Ljava/io/InterruptedIOException;")); |
| 782 | ASSERT_TRUE(HasAssignable( |
| 783 | "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true)); |
| 784 | } |
| 785 | |
| 786 | TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInBoot) { |
| 787 | ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInBoot")); |
| 788 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 789 | ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;", "x", "I", false)); |
| 790 | } |
| 791 | |
| 792 | TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInDex) { |
| 793 | ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInDex")); |
| 794 | ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false)); |
| 795 | } |
| 796 | |
| 797 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInReferenced) { |
| 798 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInReferenced")); |
| 799 | ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public")); |
| 800 | ASSERT_TRUE(HasMethod("direct", |
| 801 | "Ljava/net/Socket;", |
| 802 | "setSocketImplFactory", |
| 803 | "(Ljava/net/SocketImplFactory;)V", |
| 804 | true, |
| 805 | "public static", |
| 806 | "Ljava/net/Socket;")); |
| 807 | } |
| 808 | |
| 809 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass1) { |
| 810 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass1")); |
| 811 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract")); |
| 812 | ASSERT_TRUE(HasMethod("direct", |
| 813 | "Ljavax/net/ssl/SSLSocket;", |
| 814 | "setSocketImplFactory", |
| 815 | "(Ljava/net/SocketImplFactory;)V", |
| 816 | true, |
| 817 | "public static", |
| 818 | "Ljava/net/Socket;")); |
| 819 | } |
| 820 | |
| 821 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass2) { |
| 822 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass2")); |
| 823 | ASSERT_TRUE(HasMethod("direct", |
| 824 | "LMySSLSocket;", |
| 825 | "setSocketImplFactory", |
| 826 | "(Ljava/net/SocketImplFactory;)V", |
| 827 | true, |
| 828 | "public static", |
| 829 | "Ljava/net/Socket;")); |
| 830 | } |
| 831 | |
| 832 | TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface1) { |
| 833 | ASSERT_TRUE(VerifyMethod("InvokeStatic_DeclaredInInterface1")); |
| 834 | ASSERT_TRUE(HasClass("Ljava/util/Map$Entry;", true, "public abstract interface")); |
| 835 | ASSERT_TRUE(HasMethod("direct", |
| 836 | "Ljava/util/Map$Entry;", |
| 837 | "comparingByKey", |
| 838 | "()Ljava/util/Comparator;", |
| 839 | true, |
| 840 | "public static", |
| 841 | "Ljava/util/Map$Entry;")); |
| 842 | } |
| 843 | |
| 844 | TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface2) { |
| 845 | ASSERT_FALSE(VerifyMethod("InvokeStatic_DeclaredInInterface2")); |
| 846 | ASSERT_TRUE(HasClass("Ljava/util/AbstractMap$SimpleEntry;", true, "public")); |
| 847 | ASSERT_TRUE(HasMethod("direct", |
| 848 | "Ljava/util/AbstractMap$SimpleEntry;", |
| 849 | "comparingByKey", |
| 850 | "()Ljava/util/Comparator;", |
| 851 | false)); |
| 852 | } |
| 853 | |
| 854 | TEST_F(VerifierDepsTest, InvokeStatic_Unresolved1) { |
| 855 | ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved1")); |
| 856 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract")); |
| 857 | ASSERT_TRUE(HasMethod("direct", "Ljavax/net/ssl/SSLSocket;", "x", "()V", false)); |
| 858 | } |
| 859 | |
| 860 | TEST_F(VerifierDepsTest, InvokeStatic_Unresolved2) { |
| 861 | ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved2")); |
| 862 | ASSERT_TRUE(HasMethod("direct", "LMySSLSocket;", "x", "()V", false)); |
| 863 | } |
| 864 | |
| 865 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInReferenced) { |
| 866 | ASSERT_TRUE(VerifyMethod("InvokeDirect_Resolved_DeclaredInReferenced")); |
| 867 | ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public")); |
| 868 | ASSERT_TRUE(HasMethod( |
| 869 | "direct", "Ljava/net/Socket;", "<init>", "()V", true, "public", "Ljava/net/Socket;")); |
| 870 | } |
| 871 | |
| 872 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass1) { |
| 873 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass1")); |
| 874 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract")); |
| 875 | ASSERT_TRUE(HasMethod("direct", |
| 876 | "Ljavax/net/ssl/SSLSocket;", |
| 877 | "checkOldImpl", |
| 878 | "()V", |
| 879 | true, |
| 880 | "private", |
| 881 | "Ljava/net/Socket;")); |
| 882 | } |
| 883 | |
| 884 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass2) { |
| 885 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass2")); |
| 886 | ASSERT_TRUE(HasMethod( |
| 887 | "direct", "LMySSLSocket;", "checkOldImpl", "()V", true, "private", "Ljava/net/Socket;")); |
| 888 | } |
| 889 | |
| 890 | TEST_F(VerifierDepsTest, InvokeDirect_Unresolved1) { |
| 891 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved1")); |
| 892 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract")); |
| 893 | ASSERT_TRUE(HasMethod("direct", "Ljavax/net/ssl/SSLSocket;", "x", "()V", false)); |
| 894 | } |
| 895 | |
| 896 | TEST_F(VerifierDepsTest, InvokeDirect_Unresolved2) { |
| 897 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved2")); |
| 898 | ASSERT_TRUE(HasMethod("direct", "LMySSLSocket;", "x", "()V", false)); |
| 899 | } |
| 900 | |
| 901 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInReferenced) { |
| 902 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInReferenced")); |
| 903 | ASSERT_TRUE(HasClass("Ljava/lang/Throwable;", true, "public")); |
| 904 | ASSERT_TRUE(HasMethod("virtual", |
| 905 | "Ljava/lang/Throwable;", |
| 906 | "getMessage", |
| 907 | "()Ljava/lang/String;", |
| 908 | true, |
| 909 | "public", |
| 910 | "Ljava/lang/Throwable;")); |
| 911 | // Type dependency on `this` argument. |
| 912 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "LMySocketTimeoutException;", true)); |
| 913 | } |
| 914 | |
| 915 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass1) { |
| 916 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass1")); |
| 917 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 918 | ASSERT_TRUE(HasMethod("virtual", |
| 919 | "Ljava/io/InterruptedIOException;", |
| 920 | "getMessage", |
| 921 | "()Ljava/lang/String;", |
| 922 | true, |
| 923 | "public", |
| 924 | "Ljava/lang/Throwable;")); |
| 925 | // Type dependency on `this` argument. |
| 926 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "LMySocketTimeoutException;", true)); |
| 927 | } |
| 928 | |
| 929 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass2) { |
| 930 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass2")); |
| 931 | ASSERT_TRUE(HasMethod("virtual", |
| 932 | "LMySocketTimeoutException;", |
| 933 | "getMessage", |
| 934 | "()Ljava/lang/String;", |
| 935 | true, |
| 936 | "public", |
| 937 | "Ljava/lang/Throwable;")); |
| 938 | } |
| 939 | |
| 940 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperinterface) { |
| 941 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperinterface")); |
| 942 | ASSERT_TRUE(HasMethod("virtual", |
| 943 | "LMyThreadSet;", |
| 944 | "size", |
| 945 | "()I", |
| 946 | true, |
| 947 | "public abstract", |
| 948 | "Ljava/util/Set;")); |
| 949 | } |
| 950 | |
| 951 | TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved1) { |
| 952 | ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved1")); |
| 953 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 954 | ASSERT_TRUE(HasMethod("virtual", "Ljava/io/InterruptedIOException;", "x", "()V", false)); |
| 955 | } |
| 956 | |
| 957 | TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved2) { |
| 958 | ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved2")); |
| 959 | ASSERT_TRUE(HasMethod("virtual", "LMySocketTimeoutException;", "x", "()V", false)); |
| 960 | } |
| 961 | |
| 962 | TEST_F(VerifierDepsTest, InvokeVirtual_ActuallyDirect) { |
| 963 | ASSERT_FALSE(VerifyMethod("InvokeVirtual_ActuallyDirect")); |
| 964 | ASSERT_TRUE(HasMethod("virtual", "LMyThread;", "activeCount", "()I", false)); |
| 965 | ASSERT_TRUE(HasMethod("direct", |
| 966 | "LMyThread;", |
| 967 | "activeCount", |
| 968 | "()I", |
| 969 | true, |
| 970 | "public static", |
| 971 | "Ljava/lang/Thread;")); |
| 972 | } |
| 973 | |
| 974 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInReferenced) { |
| 975 | ASSERT_TRUE(VerifyMethod("InvokeInterface_Resolved_DeclaredInReferenced")); |
| 976 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface")); |
| 977 | ASSERT_TRUE(HasMethod("interface", |
| 978 | "Ljava/lang/Runnable;", |
| 979 | "run", |
| 980 | "()V", |
| 981 | true, |
| 982 | "public abstract", |
| 983 | "Ljava/lang/Runnable;")); |
| 984 | } |
| 985 | |
| 986 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperclass) { |
| 987 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperclass")); |
| 988 | ASSERT_TRUE(HasMethod("interface", "LMyThread;", "join", "()V", false)); |
| 989 | } |
| 990 | |
| 991 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface1) { |
| 992 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface1")); |
| 993 | ASSERT_TRUE(HasMethod("interface", |
| 994 | "LMyThreadSet;", |
| 995 | "run", |
| 996 | "()V", |
| 997 | true, |
| 998 | "public abstract", |
| 999 | "Ljava/lang/Runnable;")); |
| 1000 | } |
| 1001 | |
| 1002 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface2) { |
| 1003 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface2")); |
| 1004 | ASSERT_TRUE(HasMethod("interface", |
| 1005 | "LMyThreadSet;", |
| 1006 | "isEmpty", |
| 1007 | "()Z", |
| 1008 | true, |
| 1009 | "public abstract", |
| 1010 | "Ljava/util/Set;")); |
| 1011 | } |
| 1012 | |
| 1013 | TEST_F(VerifierDepsTest, InvokeInterface_Unresolved1) { |
| 1014 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved1")); |
| 1015 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface")); |
| 1016 | ASSERT_TRUE(HasMethod("interface", "Ljava/lang/Runnable;", "x", "()V", false)); |
| 1017 | } |
| 1018 | |
| 1019 | TEST_F(VerifierDepsTest, InvokeInterface_Unresolved2) { |
| 1020 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved2")); |
| 1021 | ASSERT_TRUE(HasMethod("interface", "LMyThreadSet;", "x", "()V", false)); |
| 1022 | } |
| 1023 | |
| 1024 | TEST_F(VerifierDepsTest, InvokeSuper_ThisAssignable) { |
| 1025 | ASSERT_TRUE(VerifyMethod("InvokeSuper_ThisAssignable")); |
| 1026 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface")); |
| 1027 | ASSERT_TRUE(HasAssignable("Ljava/lang/Runnable;", "LMain;", true)); |
| 1028 | ASSERT_TRUE(HasMethod("interface", |
| 1029 | "Ljava/lang/Runnable;", |
| 1030 | "run", |
| 1031 | "()V", |
| 1032 | true, |
| 1033 | "public abstract", |
| 1034 | "Ljava/lang/Runnable;")); |
| 1035 | } |
| 1036 | |
| 1037 | TEST_F(VerifierDepsTest, InvokeSuper_ThisNotAssignable) { |
| 1038 | ASSERT_FALSE(VerifyMethod("InvokeSuper_ThisNotAssignable")); |
| 1039 | ASSERT_TRUE(HasClass("Ljava/lang/Integer;", true, "public final")); |
| 1040 | ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "LMain;", false)); |
| 1041 | ASSERT_TRUE(HasMethod( |
| 1042 | "virtual", "Ljava/lang/Integer;", "intValue", "()I", true, "public", "Ljava/lang/Integer;")); |
| 1043 | } |
| 1044 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 1045 | TEST_F(VerifierDepsTest, EncodeDecode) { |
| 1046 | VerifyDexFile(); |
| 1047 | |
| 1048 | ASSERT_EQ(1u, NumberOfCompiledDexFiles()); |
| 1049 | ASSERT_TRUE(HasEachKindOfRecord()); |
| 1050 | |
| 1051 | std::vector<uint8_t> buffer; |
| 1052 | verifier_deps_->Encode(&buffer); |
| 1053 | ASSERT_FALSE(buffer.empty()); |
| 1054 | |
| 1055 | VerifierDeps decoded_deps({ dex_file_ }, ArrayRef<uint8_t>(buffer)); |
| 1056 | ASSERT_TRUE(verifier_deps_->Equals(decoded_deps)); |
| 1057 | } |
| 1058 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1059 | } // namespace verifier |
| 1060 | } // namespace art |