Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "class_linker.h" |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 18 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 19 | #include <memory> |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 22 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "class_linker-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 25 | #include "common_runtime_test.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 26 | #include "dex_file.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 27 | #include "entrypoints/entrypoint_utils-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 28 | #include "gc/heap.h" |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 29 | #include "mirror/abstract_method.h" |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 30 | #include "mirror/accessible_object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
| 32 | #include "mirror/dex_cache.h" |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 33 | #include "mirror/field.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | #include "mirror/object-inl.h" |
| 35 | #include "mirror/object_array-inl.h" |
| 36 | #include "mirror/proxy.h" |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 37 | #include "mirror/reference.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | #include "mirror/stack_trace_element.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 39 | #include "mirror/string-inl.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 40 | #include "handle_scope-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 41 | #include "scoped_thread_state_change.h" |
| 42 | #include "thread-inl.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 43 | |
| 44 | namespace art { |
| 45 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 46 | class ClassLinkerTest : public CommonRuntimeTest { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 47 | protected: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 48 | void AssertNonExistentClass(const std::string& descriptor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 49 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 50 | Thread* self = Thread::Current(); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 51 | EXPECT_TRUE(class_linker_->FindSystemClass(self, descriptor.c_str()) == nullptr); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 52 | EXPECT_TRUE(self->IsExceptionPending()); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 53 | mirror::Object* exception = self->GetException(); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 54 | self->ClearException(); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 55 | mirror::Class* exception_class = |
| 56 | class_linker_->FindSystemClass(self, "Ljava/lang/NoClassDefFoundError;"); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 57 | EXPECT_TRUE(exception->InstanceOf(exception_class)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 60 | void AssertPrimitiveClass(const std::string& descriptor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 61 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 62 | Thread* self = Thread::Current(); |
| 63 | AssertPrimitiveClass(descriptor, class_linker_->FindSystemClass(self, descriptor.c_str())); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 66 | void AssertPrimitiveClass(const std::string& descriptor, mirror::Class* primitive) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 67 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 68 | ASSERT_TRUE(primitive != nullptr); |
| 69 | ASSERT_TRUE(primitive->GetClass() != nullptr); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 70 | ASSERT_EQ(primitive->GetClass(), primitive->GetClass()->GetClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 71 | EXPECT_TRUE(primitive->GetClass()->GetSuperClass() != nullptr); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 72 | std::string temp; |
| 73 | ASSERT_STREQ(descriptor.c_str(), primitive->GetDescriptor(&temp)); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 74 | EXPECT_TRUE(primitive->GetSuperClass() == nullptr); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 75 | EXPECT_FALSE(primitive->HasSuperClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 76 | EXPECT_TRUE(primitive->GetClassLoader() == nullptr); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 77 | EXPECT_EQ(mirror::Class::kStatusInitialized, primitive->GetStatus()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 78 | EXPECT_FALSE(primitive->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 79 | EXPECT_TRUE(primitive->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 80 | EXPECT_TRUE(primitive->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 81 | EXPECT_TRUE(primitive->IsVerified()); |
| 82 | EXPECT_TRUE(primitive->IsInitialized()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 83 | EXPECT_FALSE(primitive->IsArrayInstance()); |
| 84 | EXPECT_FALSE(primitive->IsArrayClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 85 | EXPECT_TRUE(primitive->GetComponentType() == nullptr); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 86 | EXPECT_FALSE(primitive->IsInterface()); |
| 87 | EXPECT_TRUE(primitive->IsPublic()); |
| 88 | EXPECT_TRUE(primitive->IsFinal()); |
| 89 | EXPECT_TRUE(primitive->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 90 | EXPECT_FALSE(primitive->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 91 | EXPECT_EQ(0U, primitive->NumDirectMethods()); |
| 92 | EXPECT_EQ(0U, primitive->NumVirtualMethods()); |
| 93 | EXPECT_EQ(0U, primitive->NumInstanceFields()); |
| 94 | EXPECT_EQ(0U, primitive->NumStaticFields()); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 95 | EXPECT_EQ(0U, primitive->NumDirectInterfaces()); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 96 | EXPECT_FALSE(primitive->HasVTable()); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 97 | EXPECT_EQ(0, primitive->GetIfTableCount()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 98 | EXPECT_TRUE(primitive->GetIfTable() == nullptr); |
Elliott Hughes | 00626c2 | 2013-06-14 15:04:14 -0700 | [diff] [blame] | 99 | EXPECT_EQ(kAccPublic | kAccFinal | kAccAbstract, primitive->GetAccessFlags()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 102 | void AssertArrayClass(const std::string& array_descriptor, |
| 103 | const std::string& component_type, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 104 | mirror::ClassLoader* class_loader) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 105 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 106 | Thread* self = Thread::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 107 | StackHandleScope<2> hs(self); |
| 108 | Handle<mirror::ClassLoader> loader(hs.NewHandle(class_loader)); |
| 109 | Handle<mirror::Class> array( |
| 110 | hs.NewHandle(class_linker_->FindClass(self, array_descriptor.c_str(), loader))); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 111 | std::string temp; |
| 112 | EXPECT_STREQ(component_type.c_str(), array->GetComponentType()->GetDescriptor(&temp)); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 113 | EXPECT_EQ(class_loader, array->GetClassLoader()); |
Elliott Hughes | 00626c2 | 2013-06-14 15:04:14 -0700 | [diff] [blame] | 114 | EXPECT_EQ(kAccFinal | kAccAbstract, (array->GetAccessFlags() & (kAccFinal | kAccAbstract))); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 115 | AssertArrayClass(array_descriptor, array); |
| 116 | } |
| 117 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 118 | void AssertArrayClass(const std::string& array_descriptor, Handle<mirror::Class> array) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 119 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 120 | ASSERT_TRUE(array.Get() != nullptr); |
| 121 | ASSERT_TRUE(array->GetClass() != nullptr); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 122 | ASSERT_EQ(array->GetClass(), array->GetClass()->GetClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 123 | EXPECT_TRUE(array->GetClass()->GetSuperClass() != nullptr); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 124 | std::string temp; |
| 125 | ASSERT_STREQ(array_descriptor.c_str(), array->GetDescriptor(&temp)); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 126 | EXPECT_TRUE(array->GetSuperClass() != nullptr); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 127 | Thread* self = Thread::Current(); |
| 128 | EXPECT_EQ(class_linker_->FindSystemClass(self, "Ljava/lang/Object;"), array->GetSuperClass()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 129 | EXPECT_TRUE(array->HasSuperClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 130 | ASSERT_TRUE(array->GetComponentType() != nullptr); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 131 | ASSERT_GT(strlen(array->GetComponentType()->GetDescriptor(&temp)), 0U); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 132 | EXPECT_EQ(mirror::Class::kStatusInitialized, array->GetStatus()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 133 | EXPECT_FALSE(array->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 134 | EXPECT_TRUE(array->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 135 | EXPECT_TRUE(array->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 136 | EXPECT_TRUE(array->IsVerified()); |
| 137 | EXPECT_TRUE(array->IsInitialized()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 138 | EXPECT_FALSE(array->IsArrayInstance()); |
| 139 | EXPECT_TRUE(array->IsArrayClass()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 140 | EXPECT_FALSE(array->IsInterface()); |
| 141 | EXPECT_EQ(array->GetComponentType()->IsPublic(), array->IsPublic()); |
| 142 | EXPECT_TRUE(array->IsFinal()); |
| 143 | EXPECT_FALSE(array->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 144 | EXPECT_FALSE(array->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 145 | EXPECT_EQ(0U, array->NumDirectMethods()); |
| 146 | EXPECT_EQ(0U, array->NumVirtualMethods()); |
| 147 | EXPECT_EQ(0U, array->NumInstanceFields()); |
| 148 | EXPECT_EQ(0U, array->NumStaticFields()); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 149 | EXPECT_EQ(2U, array->NumDirectInterfaces()); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 150 | EXPECT_TRUE(array->ShouldHaveEmbeddedImtAndVTable()); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 151 | EXPECT_EQ(2, array->GetIfTableCount()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 152 | ASSERT_TRUE(array->GetIfTable() != nullptr); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 153 | mirror::Class* direct_interface0 = mirror::Class::GetDirectInterface(self, array, 0); |
| 154 | EXPECT_TRUE(direct_interface0 != nullptr); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 155 | EXPECT_STREQ(direct_interface0->GetDescriptor(&temp), "Ljava/lang/Cloneable;"); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 156 | mirror::Class* direct_interface1 = mirror::Class::GetDirectInterface(self, array, 1); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 157 | EXPECT_STREQ(direct_interface1->GetDescriptor(&temp), "Ljava/io/Serializable;"); |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 158 | mirror::Class* array_ptr = array->GetComponentType(); |
| 159 | EXPECT_EQ(class_linker_->FindArrayClass(self, &array_ptr), array.Get()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 160 | } |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 161 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 162 | void AssertMethod(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 163 | EXPECT_TRUE(method != nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 164 | EXPECT_TRUE(method->GetDeclaringClass() != nullptr); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 165 | EXPECT_TRUE(method->GetName() != nullptr); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 166 | EXPECT_TRUE(method->GetSignature() != Signature::NoSignature()); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 167 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame^] | 168 | EXPECT_TRUE(method->HasDexCacheResolvedMethods(sizeof(void*))); |
| 169 | EXPECT_TRUE(method->HasDexCacheResolvedTypes(sizeof(void*))); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 170 | EXPECT_TRUE(method->HasSameDexCacheResolvedMethods( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame^] | 171 | method->GetDeclaringClass()->GetDexCache()->GetResolvedMethods(), |
| 172 | sizeof(void*))); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 173 | EXPECT_TRUE(method->HasSameDexCacheResolvedTypes( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame^] | 174 | method->GetDeclaringClass()->GetDexCache()->GetResolvedTypes(), |
| 175 | sizeof(void*))); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 178 | void AssertField(mirror::Class* klass, ArtField* field) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 179 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 180 | EXPECT_TRUE(field != nullptr); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 181 | EXPECT_EQ(klass, field->GetDeclaringClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 182 | EXPECT_TRUE(field->GetName() != nullptr); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 183 | EXPECT_TRUE(field->GetType<true>() != nullptr); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 186 | void AssertClass(const std::string& descriptor, Handle<mirror::Class> klass) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 187 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 188 | std::string temp; |
| 189 | EXPECT_STREQ(descriptor.c_str(), klass->GetDescriptor(&temp)); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 190 | if (descriptor == "Ljava/lang/Object;") { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 191 | EXPECT_FALSE(klass->HasSuperClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 192 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 193 | EXPECT_TRUE(klass->HasSuperClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 194 | EXPECT_TRUE(klass->GetSuperClass() != nullptr); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 195 | } |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 196 | EXPECT_TRUE(klass->GetClass() != nullptr); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 197 | EXPECT_EQ(klass->GetClass(), klass->GetClass()->GetClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 198 | EXPECT_TRUE(klass->GetDexCache() != nullptr); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 199 | EXPECT_TRUE(klass->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 200 | EXPECT_TRUE(klass->IsResolved()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 201 | EXPECT_FALSE(klass->IsErroneous()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 202 | EXPECT_FALSE(klass->IsArrayClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 203 | EXPECT_TRUE(klass->GetComponentType() == nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 204 | EXPECT_TRUE(klass->IsInSamePackage(klass.Get())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 205 | EXPECT_TRUE(klass->GetDexCacheStrings() != nullptr); |
| 206 | EXPECT_EQ(klass->GetDexCacheStrings(), klass->GetDexCache()->GetStrings()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 207 | std::string temp2; |
| 208 | EXPECT_TRUE(mirror::Class::IsInSamePackage(klass->GetDescriptor(&temp), |
| 209 | klass->GetDescriptor(&temp2))); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 210 | if (klass->IsInterface()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(klass->IsAbstract()); |
| 212 | if (klass->NumDirectMethods() == 1) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 213 | EXPECT_TRUE(klass->GetDirectMethod(0, sizeof(void*))->IsClassInitializer()); |
| 214 | EXPECT_TRUE(klass->GetDirectMethod(0, sizeof(void*))->IsDirect()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 215 | } else { |
| 216 | EXPECT_EQ(0U, klass->NumDirectMethods()); |
| 217 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 218 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 219 | if (!klass->IsSynthetic()) { |
| 220 | EXPECT_NE(0U, klass->NumDirectMethods()); |
| 221 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 222 | } |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 223 | EXPECT_EQ(klass->IsInterface(), !klass->HasVTable()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 224 | mirror::IfTable* iftable = klass->GetIfTable(); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 225 | for (int i = 0; i < klass->GetIfTableCount(); i++) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 226 | mirror::Class* interface = iftable->GetInterface(i); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 227 | ASSERT_TRUE(interface != nullptr); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 228 | if (klass->IsInterface()) { |
Ian Rogers | 9bc8191 | 2012-10-11 21:43:36 -0700 | [diff] [blame] | 229 | EXPECT_EQ(0U, iftable->GetMethodArrayCount(i)); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 230 | } else { |
Ian Rogers | 9bc8191 | 2012-10-11 21:43:36 -0700 | [diff] [blame] | 231 | EXPECT_EQ(interface->NumVirtualMethods(), iftable->GetMethodArrayCount(i)); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 234 | if (klass->IsAbstract()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 235 | EXPECT_FALSE(klass->IsFinal()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 236 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 237 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 238 | } |
| 239 | if (klass->IsFinal()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 240 | EXPECT_FALSE(klass->IsAbstract()); |
| 241 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 242 | } |
| 243 | if (klass->IsAnnotation()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 244 | EXPECT_FALSE(klass->IsFinal()); |
| 245 | EXPECT_TRUE(klass->IsAbstract()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | EXPECT_FALSE(klass->IsPrimitive()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 249 | EXPECT_TRUE(klass->CanAccess(klass.Get())); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 250 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 251 | for (ArtMethod& method : klass->GetDirectMethods(sizeof(void*))) { |
| 252 | AssertMethod(&method); |
| 253 | EXPECT_TRUE(method.IsDirect()); |
| 254 | EXPECT_EQ(klass.Get(), method.GetDeclaringClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 257 | for (ArtMethod& method : klass->GetVirtualMethods(sizeof(void*))) { |
| 258 | AssertMethod(&method); |
| 259 | EXPECT_FALSE(method.IsDirect()); |
| 260 | EXPECT_TRUE(method.GetDeclaringClass()->IsAssignableFrom(klass.Get())); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | for (size_t i = 0; i < klass->NumInstanceFields(); i++) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 264 | ArtField* field = klass->GetInstanceField(i); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 265 | AssertField(klass.Get(), field); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 266 | EXPECT_FALSE(field->IsStatic()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | for (size_t i = 0; i < klass->NumStaticFields(); i++) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 270 | ArtField* field = klass->GetStaticField(i); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 271 | AssertField(klass.Get(), field); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 272 | EXPECT_TRUE(field->IsStatic()); |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 273 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 274 | |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 275 | // Confirm that all instances field offsets are packed together at the start. |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 276 | EXPECT_GE(klass->NumInstanceFields(), klass->NumReferenceInstanceFields()); |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 277 | MemberOffset start_ref_offset = klass->GetFirstReferenceInstanceFieldOffset(); |
| 278 | MemberOffset end_ref_offset(start_ref_offset.Uint32Value() + |
| 279 | klass->NumReferenceInstanceFields() * |
| 280 | sizeof(mirror::HeapReference<mirror::Object>)); |
| 281 | MemberOffset current_ref_offset = start_ref_offset; |
| 282 | for (size_t i = 0; i < klass->NumInstanceFields(); i++) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 283 | ArtField* field = klass->GetInstanceField(i); |
| 284 | mirror::Class* field_type = field->GetType<true>(); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 285 | ASSERT_TRUE(field_type != nullptr); |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 286 | if (!field->IsPrimitiveType()) { |
| 287 | ASSERT_TRUE(!field_type->IsPrimitive()); |
| 288 | ASSERT_EQ(current_ref_offset.Uint32Value(), field->GetOffset().Uint32Value()); |
| 289 | if (current_ref_offset.Uint32Value() == end_ref_offset.Uint32Value()) { |
| 290 | // While Reference.referent is not primitive, the ClassLinker |
| 291 | // treats it as such so that the garbage collector won't scan it. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 292 | EXPECT_EQ(PrettyField(field), |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 293 | "java.lang.Object java.lang.ref.Reference.referent"); |
| 294 | } else { |
| 295 | current_ref_offset = MemberOffset(current_ref_offset.Uint32Value() + |
| 296 | sizeof(mirror::HeapReference<mirror::Object>)); |
| 297 | } |
| 298 | } else { |
| 299 | if (field->GetOffset().Uint32Value() < end_ref_offset.Uint32Value()) { |
| 300 | // Shuffled before references. |
| 301 | ASSERT_LT(field->GetOffset().Uint32Value(), start_ref_offset.Uint32Value()); |
| 302 | CHECK(!IsAligned<4>(field->GetOffset().Uint32Value())); |
| 303 | } |
Brian Carlstrom | fbfdce6 | 2011-10-05 17:33:32 -0700 | [diff] [blame] | 304 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 305 | } |
Vladimir Marko | 76649e8 | 2014-11-10 18:32:59 +0000 | [diff] [blame] | 306 | ASSERT_EQ(end_ref_offset.Uint32Value(), current_ref_offset.Uint32Value()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 307 | |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 308 | uint32_t total_num_reference_instance_fields = 0; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 309 | mirror::Class* k = klass.Get(); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 310 | while (k != nullptr) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 311 | total_num_reference_instance_fields += k->NumReferenceInstanceFields(); |
| 312 | k = k->GetSuperClass(); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 313 | } |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 314 | EXPECT_GE(total_num_reference_instance_fields, 1U); // Should always have Object's class. |
| 315 | if (klass->GetReferenceInstanceOffsets() != mirror::Class::kClassWalkSuper) { |
| 316 | // The reference instance offsets have a bit set for each reference offset. |
| 317 | // +1 for Object's class. |
| 318 | EXPECT_EQ(static_cast<uint32_t>(POPCOUNT(klass->GetReferenceInstanceOffsets())) + 1, |
| 319 | total_num_reference_instance_fields); |
| 320 | } |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 323 | void AssertDexFileClass(mirror::ClassLoader* class_loader, const std::string& descriptor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 324 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 325 | ASSERT_TRUE(descriptor != nullptr); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 326 | Thread* self = Thread::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 327 | StackHandleScope<1> hs(self); |
| 328 | Handle<mirror::Class> klass( |
| 329 | hs.NewHandle(class_linker_->FindSystemClass(self, descriptor.c_str()))); |
| 330 | ASSERT_TRUE(klass.Get() != nullptr); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 331 | std::string temp; |
| 332 | EXPECT_STREQ(descriptor.c_str(), klass.Get()->GetDescriptor(&temp)); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 333 | EXPECT_EQ(class_loader, klass->GetClassLoader()); |
| 334 | if (klass->IsPrimitive()) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 335 | AssertPrimitiveClass(descriptor, klass.Get()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 336 | } else if (klass->IsArrayClass()) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 337 | AssertArrayClass(descriptor, klass); |
| 338 | } else { |
| 339 | AssertClass(descriptor, klass); |
| 340 | } |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 343 | void AssertDexFile(const DexFile& dex, mirror::ClassLoader* class_loader) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 344 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 345 | // Verify all the classes defined in this file |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 346 | for (size_t i = 0; i < dex.NumClassDefs(); i++) { |
| 347 | const DexFile::ClassDef& class_def = dex.GetClassDef(i); |
| 348 | const char* descriptor = dex.GetClassDescriptor(class_def); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 349 | AssertDexFileClass(class_loader, descriptor); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 350 | } |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 351 | // Verify all the types referenced by this file |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 352 | for (size_t i = 0; i < dex.NumTypeIds(); i++) { |
| 353 | const DexFile::TypeId& type_id = dex.GetTypeId(i); |
| 354 | const char* descriptor = dex.GetTypeDescriptor(type_id); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 355 | AssertDexFileClass(class_loader, descriptor); |
| 356 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 357 | TestRootVisitor visitor; |
| 358 | class_linker_->VisitRoots(&visitor, kVisitRootFlagAllRoots); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 359 | // Verify the dex cache has resolution methods in all resolved method slots |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 360 | mirror::DexCache* dex_cache = class_linker_->FindDexCache(Thread::Current(), dex); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 361 | auto* resolved_methods = dex_cache->GetResolvedMethods(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame^] | 362 | for (size_t i = 0, num_methods = dex_cache->NumResolvedMethods(); i != num_methods; ++i) { |
| 363 | EXPECT_TRUE( |
| 364 | mirror::DexCache::GetElementPtrSize(resolved_methods, i, sizeof(void*)) != nullptr) |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 365 | << dex.GetLocation() << " i=" << i; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 366 | } |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 367 | } |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 368 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 369 | class TestRootVisitor : public SingleRootVisitor { |
| 370 | public: |
| 371 | void VisitRoot(mirror::Object* root, const RootInfo& info ATTRIBUTE_UNUSED) OVERRIDE { |
| 372 | EXPECT_TRUE(root != nullptr); |
| 373 | } |
| 374 | }; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 375 | }; |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 376 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 377 | struct CheckOffset { |
| 378 | size_t cpp_offset; |
| 379 | const char* java_name; |
| 380 | CheckOffset(size_t c, const char* j) : cpp_offset(c), java_name(j) {} |
| 381 | }; |
| 382 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 383 | template <typename T> |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 384 | struct CheckOffsets { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 385 | CheckOffsets(bool is_static_in, const char* class_descriptor_in) |
| 386 | : is_static(is_static_in), class_descriptor(class_descriptor_in) {} |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 387 | bool is_static; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 388 | std::string class_descriptor; |
| 389 | std::vector<CheckOffset> offsets; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 390 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 391 | bool Check() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 392 | Thread* self = Thread::Current(); |
| 393 | mirror::Class* klass = |
| 394 | Runtime::Current()->GetClassLinker()->FindSystemClass(self, class_descriptor.c_str()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 395 | CHECK(klass != nullptr) << class_descriptor; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 396 | |
| 397 | bool error = false; |
| 398 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 399 | // Classes have a different size due to padding field. Strings are variable length. |
| 400 | if (!klass->IsClassClass() && !klass->IsStringClass() && !is_static) { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 401 | // Currently only required for AccessibleObject since of the padding fields. The class linker |
| 402 | // says AccessibleObject is 9 bytes but sizeof(AccessibleObject) is 12 bytes due to padding. |
| 403 | // The RoundUp is to get around this case. |
| 404 | static constexpr size_t kPackAlignment = 4; |
| 405 | size_t expected_size = RoundUp(is_static ? klass->GetClassSize(): klass->GetObjectSize(), |
| 406 | kPackAlignment); |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 407 | if (sizeof(T) != expected_size) { |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 408 | LOG(ERROR) << "Class size mismatch:" |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 409 | << " class=" << class_descriptor |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 410 | << " Java=" << expected_size |
| 411 | << " C++=" << sizeof(T); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 412 | error = true; |
| 413 | } |
| 414 | } |
| 415 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 416 | size_t num_fields = is_static ? klass->NumStaticFields() : klass->NumInstanceFields(); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 417 | if (offsets.size() != num_fields) { |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 418 | LOG(ERROR) << "Field count mismatch:" |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 419 | << " class=" << class_descriptor |
| 420 | << " Java=" << num_fields |
| 421 | << " C++=" << offsets.size(); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 422 | error = true; |
| 423 | } |
| 424 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 425 | for (size_t i = 0; i < offsets.size(); i++) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 426 | ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 427 | StringPiece field_name(field->GetName()); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 428 | if (field_name != offsets[i].java_name) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 429 | error = true; |
| 430 | } |
| 431 | } |
| 432 | if (error) { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 433 | for (size_t i = 0; i < offsets.size(); i++) { |
| 434 | CheckOffset& offset = offsets[i]; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 435 | ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 436 | StringPiece field_name(field->GetName()); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 437 | if (field_name != offsets[i].java_name) { |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 438 | LOG(ERROR) << "JAVA FIELD ORDER MISMATCH NEXT LINE:"; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 439 | } |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 440 | LOG(ERROR) << "Java field order:" |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 441 | << " i=" << i << " class=" << class_descriptor |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 442 | << " Java=" << field_name |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 443 | << " CheckOffsets=" << offset.java_name; |
| 444 | } |
| 445 | } |
| 446 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 447 | for (size_t i = 0; i < offsets.size(); i++) { |
| 448 | CheckOffset& offset = offsets[i]; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 449 | ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 450 | if (field->GetOffset().Uint32Value() != offset.cpp_offset) { |
| 451 | error = true; |
| 452 | } |
| 453 | } |
| 454 | if (error) { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 455 | for (size_t i = 0; i < offsets.size(); i++) { |
| 456 | CheckOffset& offset = offsets[i]; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 457 | ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 458 | if (field->GetOffset().Uint32Value() != offset.cpp_offset) { |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 459 | LOG(ERROR) << "OFFSET MISMATCH NEXT LINE:"; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 460 | } |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 461 | LOG(ERROR) << "Offset: class=" << class_descriptor << " field=" << offset.java_name |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 462 | << " Java=" << field->GetOffset().Uint32Value() << " C++=" << offset.cpp_offset; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | return !error; |
| 467 | }; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 468 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 469 | void addOffset(size_t offset, const char* name) { |
| 470 | offsets.push_back(CheckOffset(offset, name)); |
| 471 | } |
| 472 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 473 | private: |
| 474 | DISALLOW_IMPLICIT_CONSTRUCTORS(CheckOffsets); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 475 | }; |
| 476 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 477 | // Note that ClassLinkerTest.ValidateFieldOrderOfJavaCppUnionClasses |
| 478 | // is first since if it is failing, others are unlikely to succeed. |
| 479 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 480 | struct ObjectOffsets : public CheckOffsets<mirror::Object> { |
| 481 | ObjectOffsets() : CheckOffsets<mirror::Object>(false, "Ljava/lang/Object;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 482 | addOffset(OFFSETOF_MEMBER(mirror::Object, klass_), "shadow$_klass_"); |
| 483 | addOffset(OFFSETOF_MEMBER(mirror::Object, monitor_), "shadow$_monitor_"); |
Hiroshi Yamauchi | 60f63f5 | 2015-04-23 16:12:40 -0700 | [diff] [blame] | 484 | #ifdef USE_BROOKS_READ_BARRIER |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 485 | addOffset(OFFSETOF_MEMBER(mirror::Object, x_rb_ptr_), "shadow$_x_rb_ptr_"); |
| 486 | addOffset(OFFSETOF_MEMBER(mirror::Object, x_xpadding_), "shadow$_x_xpadding_"); |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 487 | #endif |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 488 | }; |
| 489 | }; |
| 490 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 491 | struct ClassOffsets : public CheckOffsets<mirror::Class> { |
| 492 | ClassOffsets() : CheckOffsets<mirror::Class>(false, "Ljava/lang/Class;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 493 | addOffset(OFFSETOF_MEMBER(mirror::Class, access_flags_), "accessFlags"); |
Mathieu Chartier | 52a7f5c | 2015-08-18 18:35:52 -0700 | [diff] [blame] | 494 | addOffset(OFFSETOF_MEMBER(mirror::Class, class_flags_), "classFlags"); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 495 | addOffset(OFFSETOF_MEMBER(mirror::Class, class_loader_), "classLoader"); |
| 496 | addOffset(OFFSETOF_MEMBER(mirror::Class, class_size_), "classSize"); |
| 497 | addOffset(OFFSETOF_MEMBER(mirror::Class, clinit_thread_id_), "clinitThreadId"); |
| 498 | addOffset(OFFSETOF_MEMBER(mirror::Class, component_type_), "componentType"); |
| 499 | addOffset(OFFSETOF_MEMBER(mirror::Class, dex_cache_), "dexCache"); |
| 500 | addOffset(OFFSETOF_MEMBER(mirror::Class, dex_cache_strings_), "dexCacheStrings"); |
| 501 | addOffset(OFFSETOF_MEMBER(mirror::Class, dex_class_def_idx_), "dexClassDefIndex"); |
| 502 | addOffset(OFFSETOF_MEMBER(mirror::Class, dex_type_idx_), "dexTypeIndex"); |
| 503 | addOffset(OFFSETOF_MEMBER(mirror::Class, direct_methods_), "directMethods"); |
| 504 | addOffset(OFFSETOF_MEMBER(mirror::Class, ifields_), "iFields"); |
| 505 | addOffset(OFFSETOF_MEMBER(mirror::Class, iftable_), "ifTable"); |
| 506 | addOffset(OFFSETOF_MEMBER(mirror::Class, name_), "name"); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 507 | addOffset(OFFSETOF_MEMBER(mirror::Class, num_reference_instance_fields_), |
| 508 | "numReferenceInstanceFields"); |
| 509 | addOffset(OFFSETOF_MEMBER(mirror::Class, num_reference_static_fields_), |
| 510 | "numReferenceStaticFields"); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 511 | addOffset(OFFSETOF_MEMBER(mirror::Class, object_size_), "objectSize"); |
| 512 | addOffset(OFFSETOF_MEMBER(mirror::Class, primitive_type_), "primitiveType"); |
| 513 | addOffset(OFFSETOF_MEMBER(mirror::Class, reference_instance_offsets_), |
| 514 | "referenceInstanceOffsets"); |
| 515 | addOffset(OFFSETOF_MEMBER(mirror::Class, sfields_), "sFields"); |
| 516 | addOffset(OFFSETOF_MEMBER(mirror::Class, status_), "status"); |
| 517 | addOffset(OFFSETOF_MEMBER(mirror::Class, super_class_), "superClass"); |
| 518 | addOffset(OFFSETOF_MEMBER(mirror::Class, verify_error_class_), "verifyErrorClass"); |
| 519 | addOffset(OFFSETOF_MEMBER(mirror::Class, virtual_methods_), "virtualMethods"); |
| 520 | addOffset(OFFSETOF_MEMBER(mirror::Class, vtable_), "vtable"); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 521 | }; |
| 522 | }; |
| 523 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 524 | struct StringOffsets : public CheckOffsets<mirror::String> { |
| 525 | StringOffsets() : CheckOffsets<mirror::String>(false, "Ljava/lang/String;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 526 | addOffset(OFFSETOF_MEMBER(mirror::String, count_), "count"); |
| 527 | addOffset(OFFSETOF_MEMBER(mirror::String, hash_code_), "hashCode"); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 528 | }; |
| 529 | }; |
| 530 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 531 | struct ThrowableOffsets : public CheckOffsets<mirror::Throwable> { |
| 532 | ThrowableOffsets() : CheckOffsets<mirror::Throwable>(false, "Ljava/lang/Throwable;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 533 | addOffset(OFFSETOF_MEMBER(mirror::Throwable, cause_), "cause"); |
| 534 | addOffset(OFFSETOF_MEMBER(mirror::Throwable, detail_message_), "detailMessage"); |
| 535 | addOffset(OFFSETOF_MEMBER(mirror::Throwable, stack_state_), "stackState"); |
| 536 | addOffset(OFFSETOF_MEMBER(mirror::Throwable, stack_trace_), "stackTrace"); |
| 537 | addOffset(OFFSETOF_MEMBER(mirror::Throwable, suppressed_exceptions_), "suppressedExceptions"); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 538 | }; |
| 539 | }; |
| 540 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 541 | struct StackTraceElementOffsets : public CheckOffsets<mirror::StackTraceElement> { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 542 | StackTraceElementOffsets() : CheckOffsets<mirror::StackTraceElement>( |
| 543 | false, "Ljava/lang/StackTraceElement;") { |
| 544 | addOffset(OFFSETOF_MEMBER(mirror::StackTraceElement, declaring_class_), "declaringClass"); |
| 545 | addOffset(OFFSETOF_MEMBER(mirror::StackTraceElement, file_name_), "fileName"); |
| 546 | addOffset(OFFSETOF_MEMBER(mirror::StackTraceElement, line_number_), "lineNumber"); |
| 547 | addOffset(OFFSETOF_MEMBER(mirror::StackTraceElement, method_name_), "methodName"); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 548 | }; |
| 549 | }; |
| 550 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 551 | struct ClassLoaderOffsets : public CheckOffsets<mirror::ClassLoader> { |
| 552 | ClassLoaderOffsets() : CheckOffsets<mirror::ClassLoader>(false, "Ljava/lang/ClassLoader;") { |
Mathieu Chartier | 6b06953 | 2015-08-05 15:08:12 -0700 | [diff] [blame] | 553 | addOffset(OFFSETOF_MEMBER(mirror::ClassLoader, class_table_), "classTable"); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 554 | addOffset(OFFSETOF_MEMBER(mirror::ClassLoader, packages_), "packages"); |
| 555 | addOffset(OFFSETOF_MEMBER(mirror::ClassLoader, parent_), "parent"); |
| 556 | addOffset(OFFSETOF_MEMBER(mirror::ClassLoader, proxyCache_), "proxyCache"); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 557 | }; |
| 558 | }; |
| 559 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 560 | struct ProxyOffsets : public CheckOffsets<mirror::Proxy> { |
| 561 | ProxyOffsets() : CheckOffsets<mirror::Proxy>(false, "Ljava/lang/reflect/Proxy;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 562 | addOffset(OFFSETOF_MEMBER(mirror::Proxy, h_), "h"); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 563 | }; |
| 564 | }; |
| 565 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 566 | struct DexCacheOffsets : public CheckOffsets<mirror::DexCache> { |
| 567 | DexCacheOffsets() : CheckOffsets<mirror::DexCache>(false, "Ljava/lang/DexCache;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 568 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, dex_), "dex"); |
| 569 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, dex_file_), "dexFile"); |
| 570 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, location_), "location"); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame^] | 571 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_fields_), "numResolvedFields"); |
| 572 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_methods_), "numResolvedMethods"); |
| 573 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_types_), "numResolvedTypes"); |
| 574 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_strings_), "numStrings"); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 575 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_fields_), "resolvedFields"); |
| 576 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_methods_), "resolvedMethods"); |
| 577 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_types_), "resolvedTypes"); |
| 578 | addOffset(OFFSETOF_MEMBER(mirror::DexCache, strings_), "strings"); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 579 | }; |
| 580 | }; |
| 581 | |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 582 | struct ReferenceOffsets : public CheckOffsets<mirror::Reference> { |
| 583 | ReferenceOffsets() : CheckOffsets<mirror::Reference>(false, "Ljava/lang/ref/Reference;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 584 | addOffset(OFFSETOF_MEMBER(mirror::Reference, pending_next_), "pendingNext"); |
| 585 | addOffset(OFFSETOF_MEMBER(mirror::Reference, queue_), "queue"); |
| 586 | addOffset(OFFSETOF_MEMBER(mirror::Reference, queue_next_), "queueNext"); |
| 587 | addOffset(OFFSETOF_MEMBER(mirror::Reference, referent_), "referent"); |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 588 | }; |
| 589 | }; |
| 590 | |
| 591 | struct FinalizerReferenceOffsets : public CheckOffsets<mirror::FinalizerReference> { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 592 | FinalizerReferenceOffsets() : CheckOffsets<mirror::FinalizerReference>( |
| 593 | false, "Ljava/lang/ref/FinalizerReference;") { |
| 594 | addOffset(OFFSETOF_MEMBER(mirror::FinalizerReference, next_), "next"); |
| 595 | addOffset(OFFSETOF_MEMBER(mirror::FinalizerReference, prev_), "prev"); |
| 596 | addOffset(OFFSETOF_MEMBER(mirror::FinalizerReference, zombie_), "zombie"); |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 597 | }; |
| 598 | }; |
| 599 | |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 600 | struct AccessibleObjectOffsets : public CheckOffsets<mirror::AccessibleObject> { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 601 | AccessibleObjectOffsets() : CheckOffsets<mirror::AccessibleObject>( |
| 602 | false, "Ljava/lang/reflect/AccessibleObject;") { |
| 603 | addOffset(mirror::AccessibleObject::FlagOffset().Uint32Value(), "flag"); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 604 | }; |
| 605 | }; |
| 606 | |
| 607 | struct FieldOffsets : public CheckOffsets<mirror::Field> { |
| 608 | FieldOffsets() : CheckOffsets<mirror::Field>(false, "Ljava/lang/reflect/Field;") { |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 609 | addOffset(OFFSETOF_MEMBER(mirror::Field, access_flags_), "accessFlags"); |
| 610 | addOffset(OFFSETOF_MEMBER(mirror::Field, declaring_class_), "declaringClass"); |
| 611 | addOffset(OFFSETOF_MEMBER(mirror::Field, dex_field_index_), "dexFieldIndex"); |
| 612 | addOffset(OFFSETOF_MEMBER(mirror::Field, offset_), "offset"); |
| 613 | addOffset(OFFSETOF_MEMBER(mirror::Field, type_), "type"); |
| 614 | }; |
| 615 | }; |
| 616 | |
| 617 | struct AbstractMethodOffsets : public CheckOffsets<mirror::AbstractMethod> { |
| 618 | AbstractMethodOffsets() : CheckOffsets<mirror::AbstractMethod>( |
| 619 | false, "Ljava/lang/reflect/AbstractMethod;") { |
| 620 | addOffset(OFFSETOF_MEMBER(mirror::AbstractMethod, access_flags_), "accessFlags"); |
| 621 | addOffset(OFFSETOF_MEMBER(mirror::AbstractMethod, art_method_), "artMethod"); |
| 622 | addOffset(OFFSETOF_MEMBER(mirror::AbstractMethod, declaring_class_), "declaringClass"); |
| 623 | addOffset(OFFSETOF_MEMBER(mirror::AbstractMethod, declaring_class_of_overridden_method_), |
| 624 | "declaringClassOfOverriddenMethod"); |
| 625 | addOffset(OFFSETOF_MEMBER(mirror::AbstractMethod, dex_method_index_), "dexMethodIndex"); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 626 | }; |
| 627 | }; |
| 628 | |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 629 | // C++ fields must exactly match the fields in the Java classes. If this fails, |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 630 | // reorder the fields in the C++ class. Managed class fields are ordered by |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 631 | // ClassLinker::LinkFields. |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 632 | TEST_F(ClassLinkerTest, ValidateFieldOrderOfJavaCppUnionClasses) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 633 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 634 | EXPECT_TRUE(ObjectOffsets().Check()); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 635 | EXPECT_TRUE(ClassOffsets().Check()); |
| 636 | EXPECT_TRUE(StringOffsets().Check()); |
| 637 | EXPECT_TRUE(ThrowableOffsets().Check()); |
| 638 | EXPECT_TRUE(StackTraceElementOffsets().Check()); |
| 639 | EXPECT_TRUE(ClassLoaderOffsets().Check()); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 640 | EXPECT_TRUE(ProxyOffsets().Check()); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 641 | EXPECT_TRUE(DexCacheOffsets().Check()); |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 642 | EXPECT_TRUE(ReferenceOffsets().Check()); |
| 643 | EXPECT_TRUE(FinalizerReferenceOffsets().Check()); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 644 | EXPECT_TRUE(AccessibleObjectOffsets().Check()); |
| 645 | EXPECT_TRUE(FieldOffsets().Check()); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 646 | EXPECT_TRUE(AbstractMethodOffsets().Check()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 649 | TEST_F(ClassLinkerTest, FindClassNonexistent) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 650 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 651 | AssertNonExistentClass("NoSuchClass;"); |
| 652 | AssertNonExistentClass("LNoSuchClass;"); |
| 653 | } |
| 654 | |
Andreas Gampe | 81c6f8d | 2015-03-25 17:19:53 -0700 | [diff] [blame] | 655 | TEST_F(ClassLinkerTest, GetDexFiles) { |
| 656 | ScopedObjectAccess soa(Thread::Current()); |
| 657 | |
| 658 | jobject jclass_loader = LoadDex("Nested"); |
| 659 | std::vector<const DexFile*> dex_files(GetDexFiles(jclass_loader)); |
| 660 | ASSERT_EQ(dex_files.size(), 1U); |
| 661 | EXPECT_TRUE(EndsWith(dex_files[0]->GetLocation(), "Nested.jar")); |
| 662 | |
| 663 | jobject jclass_loader2 = LoadDex("MultiDex"); |
| 664 | std::vector<const DexFile*> dex_files2(GetDexFiles(jclass_loader2)); |
| 665 | ASSERT_EQ(dex_files2.size(), 2U); |
| 666 | EXPECT_TRUE(EndsWith(dex_files2[0]->GetLocation(), "MultiDex.jar")); |
| 667 | } |
| 668 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 669 | TEST_F(ClassLinkerTest, FindClassNested) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 670 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 671 | StackHandleScope<1> hs(soa.Self()); |
| 672 | Handle<mirror::ClassLoader> class_loader( |
| 673 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("Nested")))); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 674 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 675 | mirror::Class* outer = class_linker_->FindClass(soa.Self(), "LNested;", class_loader); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 676 | ASSERT_TRUE(outer != nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 677 | EXPECT_EQ(0U, outer->NumVirtualMethods()); |
| 678 | EXPECT_EQ(1U, outer->NumDirectMethods()); |
| 679 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 680 | mirror::Class* inner = class_linker_->FindClass(soa.Self(), "LNested$Inner;", class_loader); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 681 | ASSERT_TRUE(inner != nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 682 | EXPECT_EQ(0U, inner->NumVirtualMethods()); |
| 683 | EXPECT_EQ(1U, inner->NumDirectMethods()); |
| 684 | } |
| 685 | |
| 686 | TEST_F(ClassLinkerTest, FindClass_Primitives) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 687 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 688 | const std::string expected("BCDFIJSZV"); |
Elliott Hughes | db7d5e9 | 2011-12-16 18:47:37 -0800 | [diff] [blame] | 689 | for (int ch = 1; ch < 256; ++ch) { |
| 690 | std::string descriptor; |
| 691 | descriptor.push_back(ch); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 692 | if (expected.find(ch) == std::string::npos) { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 693 | AssertNonExistentClass(descriptor); |
| 694 | } else { |
| 695 | AssertPrimitiveClass(descriptor); |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | TEST_F(ClassLinkerTest, FindClass) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 701 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 702 | mirror::Class* JavaLangObject = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 703 | ASSERT_TRUE(JavaLangObject != nullptr); |
| 704 | ASSERT_TRUE(JavaLangObject->GetClass() != nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 705 | ASSERT_EQ(JavaLangObject->GetClass(), JavaLangObject->GetClass()->GetClass()); |
| 706 | EXPECT_EQ(JavaLangObject, JavaLangObject->GetClass()->GetSuperClass()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 707 | std::string temp; |
| 708 | ASSERT_STREQ(JavaLangObject->GetDescriptor(&temp), "Ljava/lang/Object;"); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 709 | EXPECT_TRUE(JavaLangObject->GetSuperClass() == nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 710 | EXPECT_FALSE(JavaLangObject->HasSuperClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 711 | EXPECT_TRUE(JavaLangObject->GetClassLoader() == nullptr); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 712 | EXPECT_EQ(mirror::Class::kStatusInitialized, JavaLangObject->GetStatus()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 713 | EXPECT_FALSE(JavaLangObject->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 714 | EXPECT_TRUE(JavaLangObject->IsLoaded()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 715 | EXPECT_TRUE(JavaLangObject->IsResolved()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 716 | EXPECT_TRUE(JavaLangObject->IsVerified()); |
| 717 | EXPECT_TRUE(JavaLangObject->IsInitialized()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 718 | EXPECT_FALSE(JavaLangObject->IsArrayInstance()); |
| 719 | EXPECT_FALSE(JavaLangObject->IsArrayClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 720 | EXPECT_TRUE(JavaLangObject->GetComponentType() == nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 721 | EXPECT_FALSE(JavaLangObject->IsInterface()); |
| 722 | EXPECT_TRUE(JavaLangObject->IsPublic()); |
| 723 | EXPECT_FALSE(JavaLangObject->IsFinal()); |
| 724 | EXPECT_FALSE(JavaLangObject->IsPrimitive()); |
| 725 | EXPECT_FALSE(JavaLangObject->IsSynthetic()); |
| 726 | EXPECT_EQ(2U, JavaLangObject->NumDirectMethods()); |
| 727 | EXPECT_EQ(11U, JavaLangObject->NumVirtualMethods()); |
Hiroshi Yamauchi | 60f63f5 | 2015-04-23 16:12:40 -0700 | [diff] [blame] | 728 | if (!kUseBrooksReadBarrier) { |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 729 | EXPECT_EQ(2U, JavaLangObject->NumInstanceFields()); |
| 730 | } else { |
| 731 | EXPECT_EQ(4U, JavaLangObject->NumInstanceFields()); |
| 732 | } |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 733 | EXPECT_STREQ(JavaLangObject->GetInstanceField(0)->GetName(), "shadow$_klass_"); |
| 734 | EXPECT_STREQ(JavaLangObject->GetInstanceField(1)->GetName(), "shadow$_monitor_"); |
Hiroshi Yamauchi | 60f63f5 | 2015-04-23 16:12:40 -0700 | [diff] [blame] | 735 | if (kUseBrooksReadBarrier) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 736 | EXPECT_STREQ(JavaLangObject->GetInstanceField(2)->GetName(), "shadow$_x_rb_ptr_"); |
| 737 | EXPECT_STREQ(JavaLangObject->GetInstanceField(3)->GetName(), "shadow$_x_xpadding_"); |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 738 | } |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 739 | |
| 740 | EXPECT_EQ(0U, JavaLangObject->NumStaticFields()); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 741 | EXPECT_EQ(0U, JavaLangObject->NumDirectInterfaces()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 742 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 743 | StackHandleScope<1> hs(soa.Self()); |
| 744 | Handle<mirror::ClassLoader> class_loader( |
| 745 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("MyClass")))); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 746 | AssertNonExistentClass("LMyClass;"); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 747 | mirror::Class* MyClass = class_linker_->FindClass(soa.Self(), "LMyClass;", class_loader); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 748 | ASSERT_TRUE(MyClass != nullptr); |
| 749 | ASSERT_TRUE(MyClass->GetClass() != nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 750 | ASSERT_EQ(MyClass->GetClass(), MyClass->GetClass()->GetClass()); |
| 751 | EXPECT_EQ(JavaLangObject, MyClass->GetClass()->GetSuperClass()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 752 | ASSERT_STREQ(MyClass->GetDescriptor(&temp), "LMyClass;"); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 753 | EXPECT_TRUE(MyClass->GetSuperClass() == JavaLangObject); |
| 754 | EXPECT_TRUE(MyClass->HasSuperClass()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 755 | EXPECT_EQ(class_loader.Get(), MyClass->GetClassLoader()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 756 | EXPECT_EQ(mirror::Class::kStatusResolved, MyClass->GetStatus()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 757 | EXPECT_FALSE(MyClass->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 758 | EXPECT_TRUE(MyClass->IsLoaded()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 759 | EXPECT_TRUE(MyClass->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 760 | EXPECT_FALSE(MyClass->IsVerified()); |
| 761 | EXPECT_FALSE(MyClass->IsInitialized()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 762 | EXPECT_FALSE(MyClass->IsArrayInstance()); |
| 763 | EXPECT_FALSE(MyClass->IsArrayClass()); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 764 | EXPECT_TRUE(MyClass->GetComponentType() == nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 765 | EXPECT_FALSE(MyClass->IsInterface()); |
| 766 | EXPECT_FALSE(MyClass->IsPublic()); |
| 767 | EXPECT_FALSE(MyClass->IsFinal()); |
| 768 | EXPECT_FALSE(MyClass->IsPrimitive()); |
| 769 | EXPECT_FALSE(MyClass->IsSynthetic()); |
| 770 | EXPECT_EQ(1U, MyClass->NumDirectMethods()); |
| 771 | EXPECT_EQ(0U, MyClass->NumVirtualMethods()); |
| 772 | EXPECT_EQ(0U, MyClass->NumInstanceFields()); |
| 773 | EXPECT_EQ(0U, MyClass->NumStaticFields()); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 774 | EXPECT_EQ(0U, MyClass->NumDirectInterfaces()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 775 | |
| 776 | EXPECT_EQ(JavaLangObject->GetClass()->GetClass(), MyClass->GetClass()->GetClass()); |
| 777 | |
| 778 | // created by class_linker |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 779 | AssertArrayClass("[C", "C", nullptr); |
| 780 | AssertArrayClass("[Ljava/lang/Object;", "Ljava/lang/Object;", nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 781 | // synthesized on the fly |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 782 | AssertArrayClass("[[C", "[C", nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 783 | AssertArrayClass("[[[LMyClass;", "[[LMyClass;", class_loader.Get()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 784 | // or not available at all |
| 785 | AssertNonExistentClass("[[[[LNonExistentClass;"); |
| 786 | } |
| 787 | |
| 788 | TEST_F(ClassLinkerTest, LibCore) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 789 | ScopedObjectAccess soa(Thread::Current()); |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 790 | ASSERT_TRUE(java_lang_dex_file_ != nullptr); |
| 791 | AssertDexFile(*java_lang_dex_file_, nullptr); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 794 | // The first reference array element must be a multiple of 4 bytes from the |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 795 | // start of the object |
| 796 | TEST_F(ClassLinkerTest, ValidateObjectArrayElementsOffset) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 797 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 798 | mirror::Class* array_class = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/String;"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 799 | mirror::ObjectArray<mirror::String>* array = |
| 800 | mirror::ObjectArray<mirror::String>::Alloc(soa.Self(), array_class, 0); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 801 | uintptr_t data_offset = |
| 802 | reinterpret_cast<uintptr_t>(array->GetRawData(sizeof(mirror::HeapReference<mirror::String>), |
| 803 | 0)); |
| 804 | if (sizeof(mirror::HeapReference<mirror::String>) == sizeof(int32_t)) { |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 805 | EXPECT_TRUE(IsAligned<4>(data_offset)); // Check 4 byte alignment. |
| 806 | } else { |
| 807 | EXPECT_TRUE(IsAligned<8>(data_offset)); // Check 8 byte alignment. |
| 808 | } |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | TEST_F(ClassLinkerTest, ValidatePrimitiveArrayElementsOffset) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 812 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 813 | StackHandleScope<5> hs(soa.Self()); |
| 814 | Handle<mirror::LongArray> long_array(hs.NewHandle(mirror::LongArray::Alloc(soa.Self(), 0))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 815 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[J"), long_array->GetClass()); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 816 | uintptr_t data_offset = reinterpret_cast<uintptr_t>(long_array->GetData()); |
| 817 | EXPECT_TRUE(IsAligned<8>(data_offset)); // Longs require 8 byte alignment |
| 818 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 819 | Handle<mirror::DoubleArray> double_array(hs.NewHandle(mirror::DoubleArray::Alloc(soa.Self(), 0))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 820 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[D"), double_array->GetClass()); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 821 | data_offset = reinterpret_cast<uintptr_t>(double_array->GetData()); |
| 822 | EXPECT_TRUE(IsAligned<8>(data_offset)); // Doubles require 8 byte alignment |
| 823 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 824 | Handle<mirror::IntArray> int_array(hs.NewHandle(mirror::IntArray::Alloc(soa.Self(), 0))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 825 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[I"), int_array->GetClass()); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 826 | data_offset = reinterpret_cast<uintptr_t>(int_array->GetData()); |
| 827 | EXPECT_TRUE(IsAligned<4>(data_offset)); // Ints require 4 byte alignment |
| 828 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 829 | Handle<mirror::CharArray> char_array(hs.NewHandle(mirror::CharArray::Alloc(soa.Self(), 0))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 830 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[C"), char_array->GetClass()); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 831 | data_offset = reinterpret_cast<uintptr_t>(char_array->GetData()); |
| 832 | EXPECT_TRUE(IsAligned<2>(data_offset)); // Chars require 2 byte alignment |
| 833 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 834 | Handle<mirror::ShortArray> short_array(hs.NewHandle(mirror::ShortArray::Alloc(soa.Self(), 0))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 835 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[S"), short_array->GetClass()); |
Ian Rogers | a15e67d | 2012-02-28 13:51:55 -0800 | [diff] [blame] | 836 | data_offset = reinterpret_cast<uintptr_t>(short_array->GetData()); |
| 837 | EXPECT_TRUE(IsAligned<2>(data_offset)); // Shorts require 2 byte alignment |
| 838 | |
| 839 | // Take it as given that bytes and booleans have byte alignment |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 842 | TEST_F(ClassLinkerTest, ValidateBoxedTypes) { |
| 843 | // Validate that the "value" field is always the 0th field in each of java.lang's box classes. |
| 844 | // This lets UnboxPrimitive avoid searching for the field by name at runtime. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 845 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 846 | NullHandle<mirror::ClassLoader> class_loader; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 847 | mirror::Class* c; |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 848 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Boolean;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 849 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 850 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Byte;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 851 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 852 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Character;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 853 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 854 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Double;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 855 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 856 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Float;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 857 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 858 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Integer;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 859 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 860 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Long;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 861 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 862 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Short;", class_loader); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 863 | EXPECT_STREQ("value", c->GetIFieldsPtr()->At(0).GetName()); |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 866 | TEST_F(ClassLinkerTest, TwoClassLoadersOneClass) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 867 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 868 | StackHandleScope<2> hs(soa.Self()); |
| 869 | Handle<mirror::ClassLoader> class_loader_1( |
| 870 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("MyClass")))); |
| 871 | Handle<mirror::ClassLoader> class_loader_2( |
| 872 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("MyClass")))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 873 | mirror::Class* MyClass_1 = class_linker_->FindClass(soa.Self(), "LMyClass;", class_loader_1); |
| 874 | mirror::Class* MyClass_2 = class_linker_->FindClass(soa.Self(), "LMyClass;", class_loader_2); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 875 | EXPECT_TRUE(MyClass_1 != nullptr); |
| 876 | EXPECT_TRUE(MyClass_2 != nullptr); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 877 | EXPECT_NE(MyClass_1, MyClass_2); |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 878 | } |
| 879 | |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 880 | TEST_F(ClassLinkerTest, StaticFields) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 881 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 882 | StackHandleScope<2> hs(soa.Self()); |
| 883 | Handle<mirror::ClassLoader> class_loader( |
| 884 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("Statics")))); |
| 885 | Handle<mirror::Class> statics( |
| 886 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LStatics;", class_loader))); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 887 | class_linker_->EnsureInitialized(soa.Self(), statics, true, true); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 888 | |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 889 | // Static final primitives that are initialized by a compile-time constant |
| 890 | // expression resolve to a copy of a constant value from the constant pool. |
| 891 | // So <clinit> should be null. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 892 | ArtMethod* clinit = statics->FindDirectMethod("<clinit>", "()V", sizeof(void*)); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 893 | EXPECT_TRUE(clinit == nullptr); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 894 | |
| 895 | EXPECT_EQ(9U, statics->NumStaticFields()); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 896 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 897 | ArtField* s0 = mirror::Class::FindStaticField(soa.Self(), statics, "s0", "Z"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 898 | EXPECT_EQ(s0->GetTypeAsPrimitiveType(), Primitive::kPrimBoolean); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 899 | EXPECT_EQ(true, s0->GetBoolean(statics.Get())); |
| 900 | s0->SetBoolean<false>(statics.Get(), false); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 901 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 902 | ArtField* s1 = mirror::Class::FindStaticField(soa.Self(), statics, "s1", "B"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 903 | EXPECT_EQ(s1->GetTypeAsPrimitiveType(), Primitive::kPrimByte); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 904 | EXPECT_EQ(5, s1->GetByte(statics.Get())); |
| 905 | s1->SetByte<false>(statics.Get(), 6); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 906 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 907 | ArtField* s2 = mirror::Class::FindStaticField(soa.Self(), statics, "s2", "C"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 908 | EXPECT_EQ(s2->GetTypeAsPrimitiveType(), Primitive::kPrimChar); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 909 | EXPECT_EQ('a', s2->GetChar(statics.Get())); |
| 910 | s2->SetChar<false>(statics.Get(), 'b'); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 911 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 912 | ArtField* s3 = mirror::Class::FindStaticField(soa.Self(), statics, "s3", "S"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 913 | EXPECT_EQ(s3->GetTypeAsPrimitiveType(), Primitive::kPrimShort); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 914 | EXPECT_EQ(-536, s3->GetShort(statics.Get())); |
| 915 | s3->SetShort<false>(statics.Get(), -535); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 916 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 917 | ArtField* s4 = mirror::Class::FindStaticField(soa.Self(), statics, "s4", "I"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 918 | EXPECT_EQ(s4->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 919 | EXPECT_EQ(2000000000, s4->GetInt(statics.Get())); |
| 920 | s4->SetInt<false>(statics.Get(), 2000000001); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 921 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 922 | ArtField* s5 = mirror::Class::FindStaticField(soa.Self(), statics, "s5", "J"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 923 | EXPECT_EQ(s5->GetTypeAsPrimitiveType(), Primitive::kPrimLong); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 924 | EXPECT_EQ(0x1234567890abcdefLL, s5->GetLong(statics.Get())); |
| 925 | s5->SetLong<false>(statics.Get(), INT64_C(0x34567890abcdef12)); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 926 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 927 | ArtField* s6 = mirror::Class::FindStaticField(soa.Self(), statics, "s6", "F"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 928 | EXPECT_EQ(s6->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 929 | EXPECT_DOUBLE_EQ(0.5, s6->GetFloat(statics.Get())); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 930 | s6->SetFloat<false>(statics.Get(), 0.75); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 931 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 932 | ArtField* s7 = mirror::Class::FindStaticField(soa.Self(), statics, "s7", "D"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 933 | EXPECT_EQ(s7->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 934 | EXPECT_DOUBLE_EQ(16777217.0, s7->GetDouble(statics.Get())); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 935 | s7->SetDouble<false>(statics.Get(), 16777219); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 936 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 937 | ArtField* s8 = mirror::Class::FindStaticField(soa.Self(), statics, "s8", |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 938 | "Ljava/lang/String;"); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 939 | EXPECT_EQ(s8->GetTypeAsPrimitiveType(), Primitive::kPrimNot); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 940 | EXPECT_TRUE(s8->GetObject(statics.Get())->AsString()->Equals("android")); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 941 | s8->SetObject<false>(s8->GetDeclaringClass(), |
| 942 | mirror::String::AllocFromModifiedUtf8(soa.Self(), "robot")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 943 | |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 944 | // TODO: Remove EXPECT_FALSE when GCC can handle EXPECT_EQ |
| 945 | // http://code.google.com/p/googletest/issues/detail?id=322 |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 946 | EXPECT_FALSE(s0->GetBoolean(statics.Get())); |
| 947 | EXPECT_EQ(6, s1->GetByte(statics.Get())); |
| 948 | EXPECT_EQ('b', s2->GetChar(statics.Get())); |
| 949 | EXPECT_EQ(-535, s3->GetShort(statics.Get())); |
| 950 | EXPECT_EQ(2000000001, s4->GetInt(statics.Get())); |
| 951 | EXPECT_EQ(INT64_C(0x34567890abcdef12), s5->GetLong(statics.Get())); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 952 | EXPECT_FLOAT_EQ(0.75, s6->GetFloat(statics.Get())); |
| 953 | EXPECT_DOUBLE_EQ(16777219.0, s7->GetDouble(statics.Get())); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 954 | EXPECT_TRUE(s8->GetObject(statics.Get())->AsString()->Equals("robot")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 957 | TEST_F(ClassLinkerTest, Interfaces) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 958 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 959 | StackHandleScope<6> hs(soa.Self()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 960 | Handle<mirror::ClassLoader> class_loader( |
| 961 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("Interfaces")))); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 962 | Handle<mirror::Class> I( |
| 963 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInterfaces$I;", class_loader))); |
| 964 | Handle<mirror::Class> J( |
| 965 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInterfaces$J;", class_loader))); |
| 966 | Handle<mirror::Class> K( |
| 967 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInterfaces$K;", class_loader))); |
| 968 | Handle<mirror::Class> A( |
| 969 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInterfaces$A;", class_loader))); |
| 970 | Handle<mirror::Class> B( |
| 971 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInterfaces$B;", class_loader))); |
| 972 | EXPECT_TRUE(I->IsAssignableFrom(A.Get())); |
| 973 | EXPECT_TRUE(J->IsAssignableFrom(A.Get())); |
| 974 | EXPECT_TRUE(J->IsAssignableFrom(K.Get())); |
| 975 | EXPECT_TRUE(K->IsAssignableFrom(B.Get())); |
| 976 | EXPECT_TRUE(J->IsAssignableFrom(B.Get())); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 977 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 978 | const Signature void_sig = I->GetDexCache()->GetDexFile()->CreateSignature("()V"); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 979 | ArtMethod* Ii = I->FindVirtualMethod("i", void_sig, sizeof(void*)); |
| 980 | ArtMethod* Jj1 = J->FindVirtualMethod("j1", void_sig, sizeof(void*)); |
| 981 | ArtMethod* Jj2 = J->FindVirtualMethod("j2", void_sig, sizeof(void*)); |
| 982 | ArtMethod* Kj1 = K->FindInterfaceMethod("j1", void_sig, sizeof(void*)); |
| 983 | ArtMethod* Kj2 = K->FindInterfaceMethod("j2", void_sig, sizeof(void*)); |
| 984 | ArtMethod* Kk = K->FindInterfaceMethod("k", void_sig, sizeof(void*)); |
| 985 | ArtMethod* Ai = A->FindVirtualMethod("i", void_sig, sizeof(void*)); |
| 986 | ArtMethod* Aj1 = A->FindVirtualMethod("j1", void_sig, sizeof(void*)); |
| 987 | ArtMethod* Aj2 = A->FindVirtualMethod("j2", void_sig, sizeof(void*)); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 988 | ASSERT_TRUE(Ii != nullptr); |
| 989 | ASSERT_TRUE(Jj1 != nullptr); |
| 990 | ASSERT_TRUE(Jj2 != nullptr); |
| 991 | ASSERT_TRUE(Kj1 != nullptr); |
| 992 | ASSERT_TRUE(Kj2 != nullptr); |
| 993 | ASSERT_TRUE(Kk != nullptr); |
| 994 | ASSERT_TRUE(Ai != nullptr); |
| 995 | ASSERT_TRUE(Aj1 != nullptr); |
| 996 | ASSERT_TRUE(Aj2 != nullptr); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 997 | EXPECT_NE(Ii, Ai); |
| 998 | EXPECT_NE(Jj1, Aj1); |
| 999 | EXPECT_NE(Jj2, Aj2); |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 1000 | EXPECT_EQ(Kj1, Jj1); |
| 1001 | EXPECT_EQ(Kj2, Jj2); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1002 | EXPECT_EQ(Ai, A->FindVirtualMethodForInterface(Ii, sizeof(void*))); |
| 1003 | EXPECT_EQ(Aj1, A->FindVirtualMethodForInterface(Jj1, sizeof(void*))); |
| 1004 | EXPECT_EQ(Aj2, A->FindVirtualMethodForInterface(Jj2, sizeof(void*))); |
| 1005 | EXPECT_EQ(Ai, A->FindVirtualMethodForVirtualOrInterface(Ii, sizeof(void*))); |
| 1006 | EXPECT_EQ(Aj1, A->FindVirtualMethodForVirtualOrInterface(Jj1, sizeof(void*))); |
| 1007 | EXPECT_EQ(Aj2, A->FindVirtualMethodForVirtualOrInterface(Jj2, sizeof(void*))); |
Ian Rogers | d24e264 | 2012-06-06 21:21:43 -0700 | [diff] [blame] | 1008 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1009 | ArtField* Afoo = mirror::Class::FindStaticField(soa.Self(), A, "foo", "Ljava/lang/String;"); |
| 1010 | ArtField* Bfoo = mirror::Class::FindStaticField(soa.Self(), B, "foo", "Ljava/lang/String;"); |
| 1011 | ArtField* Jfoo = mirror::Class::FindStaticField(soa.Self(), J, "foo", "Ljava/lang/String;"); |
| 1012 | ArtField* Kfoo = mirror::Class::FindStaticField(soa.Self(), K, "foo", "Ljava/lang/String;"); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1013 | ASSERT_TRUE(Afoo != nullptr); |
Ian Rogers | d24e264 | 2012-06-06 21:21:43 -0700 | [diff] [blame] | 1014 | EXPECT_EQ(Afoo, Bfoo); |
| 1015 | EXPECT_EQ(Afoo, Jfoo); |
| 1016 | EXPECT_EQ(Afoo, Kfoo); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Elliott Hughes | f3778f6 | 2012-01-26 14:14:35 -0800 | [diff] [blame] | 1019 | TEST_F(ClassLinkerTest, ResolveVerifyAndClinit) { |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 1020 | // pretend we are trying to get the static storage for the StaticsFromCode class. |
Brian Carlstrom | 193a44d | 2011-09-04 12:01:42 -0700 | [diff] [blame] | 1021 | |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 1022 | // case 1, get the uninitialized storage from StaticsFromCode.<clinit> |
| 1023 | // case 2, get the initialized storage from StaticsFromCode.getS0 |
Brian Carlstrom | 193a44d | 2011-09-04 12:01:42 -0700 | [diff] [blame] | 1024 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1025 | ScopedObjectAccess soa(Thread::Current()); |
| 1026 | jobject jclass_loader = LoadDex("StaticsFromCode"); |
Andreas Gampe | 81c6f8d | 2015-03-25 17:19:53 -0700 | [diff] [blame] | 1027 | const DexFile* dex_file = GetFirstDexFile(jclass_loader); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1028 | StackHandleScope<1> hs(soa.Self()); |
| 1029 | Handle<mirror::ClassLoader> class_loader( |
| 1030 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(jclass_loader))); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1031 | mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LStaticsFromCode;", class_loader); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1032 | ArtMethod* clinit = klass->FindClassInitializer(sizeof(void*)); |
| 1033 | ArtMethod* getS0 = klass->FindDirectMethod("getS0", "()Ljava/lang/Object;", sizeof(void*)); |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 1034 | const DexFile::StringId* string_id = dex_file->FindStringId("LStaticsFromCode;"); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1035 | ASSERT_TRUE(string_id != nullptr); |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 1036 | const DexFile::TypeId* type_id = dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1037 | ASSERT_TRUE(type_id != nullptr); |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 1038 | uint32_t type_idx = dex_file->GetIndexForTypeId(*type_id); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1039 | mirror::Class* uninit = ResolveVerifyAndClinit(type_idx, clinit, soa.Self(), true, false); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1040 | EXPECT_TRUE(uninit != nullptr); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 1041 | EXPECT_FALSE(uninit->IsInitialized()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1042 | mirror::Class* init = ResolveVerifyAndClinit(type_idx, getS0, soa.Self(), true, false); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1043 | EXPECT_TRUE(init != nullptr); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 1044 | EXPECT_TRUE(init->IsInitialized()); |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1047 | TEST_F(ClassLinkerTest, FinalizableBit) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1048 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1049 | mirror::Class* c; |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1050 | |
| 1051 | // Object has a finalize method, but we know it's empty. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1052 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1053 | EXPECT_FALSE(c->IsFinalizable()); |
| 1054 | |
| 1055 | // Enum has a finalize method to prevent its subclasses from implementing one. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1056 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Enum;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1057 | EXPECT_FALSE(c->IsFinalizable()); |
| 1058 | |
| 1059 | // RoundingMode is an enum. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1060 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/math/RoundingMode;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1061 | EXPECT_FALSE(c->IsFinalizable()); |
| 1062 | |
| 1063 | // RandomAccessFile extends Object and overrides finalize. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1064 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/RandomAccessFile;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1065 | EXPECT_TRUE(c->IsFinalizable()); |
| 1066 | |
| 1067 | // FileInputStream is finalizable and extends InputStream which isn't. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1068 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/InputStream;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1069 | EXPECT_FALSE(c->IsFinalizable()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1070 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/FileInputStream;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1071 | EXPECT_TRUE(c->IsFinalizable()); |
| 1072 | |
| 1073 | // ScheduledThreadPoolExecutor doesn't have a finalize method but |
| 1074 | // extends ThreadPoolExecutor which does. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1075 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/util/concurrent/ThreadPoolExecutor;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1076 | EXPECT_TRUE(c->IsFinalizable()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1077 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/util/concurrent/ScheduledThreadPoolExecutor;"); |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 1078 | EXPECT_TRUE(c->IsFinalizable()); |
| 1079 | } |
| 1080 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1081 | TEST_F(ClassLinkerTest, ClassRootDescriptors) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1082 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1083 | std::string temp; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1084 | for (int i = 0; i < ClassLinker::kClassRootsMax; i++) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1085 | mirror::Class* klass = class_linker_->GetClassRoot(ClassLinker::ClassRoot(i)); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1086 | EXPECT_GT(strlen(klass->GetDescriptor(&temp)), 0U); |
| 1087 | EXPECT_STREQ(klass->GetDescriptor(&temp), |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1088 | class_linker_->GetClassRootDescriptor(ClassLinker::ClassRoot(i))) << " i = " << i; |
| 1089 | } |
| 1090 | } |
| 1091 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1092 | TEST_F(ClassLinkerTest, ValidatePredefinedClassSizes) { |
| 1093 | ScopedObjectAccess soa(Thread::Current()); |
| 1094 | NullHandle<mirror::ClassLoader> class_loader; |
| 1095 | mirror::Class* c; |
| 1096 | |
| 1097 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Class;", class_loader); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1098 | ASSERT_TRUE(c != nullptr); |
| 1099 | EXPECT_EQ(c->GetClassSize(), mirror::Class::ClassClassSize(sizeof(void*))); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1100 | |
| 1101 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Object;", class_loader); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1102 | ASSERT_TRUE(c != nullptr); |
| 1103 | EXPECT_EQ(c->GetClassSize(), mirror::Object::ClassSize(sizeof(void*))); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1104 | |
| 1105 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/String;", class_loader); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1106 | ASSERT_TRUE(c != nullptr); |
| 1107 | EXPECT_EQ(c->GetClassSize(), mirror::String::ClassSize(sizeof(void*))); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1108 | |
| 1109 | c = class_linker_->FindClass(soa.Self(), "Ljava/lang/DexCache;", class_loader); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1110 | ASSERT_TRUE(c != nullptr); |
| 1111 | EXPECT_EQ(c->GetClassSize(), mirror::DexCache::ClassSize(sizeof(void*))); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1114 | static void CheckMethod(ArtMethod* method, bool verified) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1115 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1116 | if (!method->IsNative() && !method->IsAbstract()) { |
| 1117 | EXPECT_EQ((method->GetAccessFlags() & kAccPreverified) != 0U, verified) |
| 1118 | << PrettyMethod(method, true); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | static void CheckPreverified(mirror::Class* c, bool preverified) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1123 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1124 | EXPECT_EQ((c->GetAccessFlags() & kAccPreverified) != 0U, preverified) |
| 1125 | << "Class " << PrettyClass(c) << " not as expected"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1126 | for (auto& m : c->GetDirectMethods(sizeof(void*))) { |
| 1127 | CheckMethod(&m, preverified); |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1128 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1129 | for (auto& m : c->GetVirtualMethods(sizeof(void*))) { |
| 1130 | CheckMethod(&m, preverified); |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | TEST_F(ClassLinkerTest, Preverified_InitializedBoot) { |
| 1135 | ScopedObjectAccess soa(Thread::Current()); |
| 1136 | |
| 1137 | mirror::Class* JavaLangObject = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 1138 | ASSERT_TRUE(JavaLangObject != nullptr); |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1139 | EXPECT_TRUE(JavaLangObject->IsInitialized()) << "Not testing already initialized class from the " |
| 1140 | "core"; |
| 1141 | CheckPreverified(JavaLangObject, true); |
| 1142 | } |
| 1143 | |
| 1144 | TEST_F(ClassLinkerTest, Preverified_UninitializedBoot) { |
| 1145 | ScopedObjectAccess soa(Thread::Current()); |
| 1146 | |
| 1147 | StackHandleScope<1> hs(soa.Self()); |
| 1148 | |
| 1149 | Handle<mirror::Class> security_manager(hs.NewHandle(class_linker_->FindSystemClass( |
| 1150 | soa.Self(), "Ljava/lang/SecurityManager;"))); |
| 1151 | EXPECT_FALSE(security_manager->IsInitialized()) << "Not testing uninitialized class from the " |
| 1152 | "core"; |
| 1153 | |
| 1154 | CheckPreverified(security_manager.Get(), false); |
| 1155 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1156 | class_linker_->EnsureInitialized(soa.Self(), security_manager, true, true); |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1157 | CheckPreverified(security_manager.Get(), true); |
| 1158 | } |
| 1159 | |
| 1160 | TEST_F(ClassLinkerTest, Preverified_App) { |
| 1161 | ScopedObjectAccess soa(Thread::Current()); |
| 1162 | |
| 1163 | StackHandleScope<2> hs(soa.Self()); |
| 1164 | Handle<mirror::ClassLoader> class_loader( |
| 1165 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("Statics")))); |
| 1166 | Handle<mirror::Class> statics( |
| 1167 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LStatics;", class_loader))); |
| 1168 | |
| 1169 | CheckPreverified(statics.Get(), false); |
| 1170 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1171 | class_linker_->EnsureInitialized(soa.Self(), statics, true, true); |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 1172 | CheckPreverified(statics.Get(), true); |
| 1173 | } |
| 1174 | |
Sebastien Hertz | 6963e44 | 2014-11-26 22:11:27 +0100 | [diff] [blame] | 1175 | TEST_F(ClassLinkerTest, IsBootStrapClassLoaded) { |
| 1176 | ScopedObjectAccess soa(Thread::Current()); |
| 1177 | |
| 1178 | StackHandleScope<3> hs(soa.Self()); |
| 1179 | Handle<mirror::ClassLoader> class_loader( |
| 1180 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(LoadDex("Statics")))); |
| 1181 | |
| 1182 | // java.lang.Object is a bootstrap class. |
| 1183 | Handle<mirror::Class> jlo_class( |
| 1184 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
| 1185 | ASSERT_TRUE(jlo_class.Get() != nullptr); |
| 1186 | EXPECT_TRUE(jlo_class.Get()->IsBootStrapClassLoaded()); |
| 1187 | |
| 1188 | // Statics is not a bootstrap class. |
| 1189 | Handle<mirror::Class> statics( |
| 1190 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LStatics;", class_loader))); |
| 1191 | ASSERT_TRUE(statics.Get() != nullptr); |
| 1192 | EXPECT_FALSE(statics.Get()->IsBootStrapClassLoaded()); |
| 1193 | } |
| 1194 | |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 1195 | } // namespace art |