Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "class_linker.h" |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 4 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 5 | #include <string> |
| 6 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 7 | #include "UniquePtr.h" |
| 8 | #include "common_test.h" |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 9 | #include "dex_cache.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 10 | #include "dex_file.h" |
| 11 | #include "heap.h" |
Ian Rogers | ce9eca6 | 2011-10-07 17:11:03 -0700 | [diff] [blame] | 12 | #include "runtime_support.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 13 | |
| 14 | namespace art { |
| 15 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 16 | class ClassLinkerTest : public CommonTest { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | protected: |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 18 | void AssertNonExistentClass(const std::string& descriptor) { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 19 | EXPECT_TRUE(class_linker_->FindSystemClass(descriptor) == NULL); |
Elliott Hughes | 885c3bd | 2011-08-22 16:59:20 -0700 | [diff] [blame] | 20 | Thread* self = Thread::Current(); |
| 21 | EXPECT_TRUE(self->IsExceptionPending()); |
| 22 | Object* exception = self->GetException(); |
| 23 | self->ClearException(); |
| 24 | Class* exception_class = class_linker_->FindSystemClass("Ljava/lang/NoClassDefFoundError;"); |
| 25 | EXPECT_TRUE(exception->InstanceOf(exception_class)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 28 | void AssertPrimitiveClass(const std::string& descriptor) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 29 | AssertPrimitiveClass(descriptor, class_linker_->FindSystemClass(descriptor)); |
| 30 | } |
| 31 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 32 | void AssertPrimitiveClass(const std::string& descriptor, const Class* primitive) { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 33 | ASSERT_TRUE(primitive != NULL); |
| 34 | ASSERT_TRUE(primitive->GetClass() != NULL); |
| 35 | ASSERT_EQ(primitive->GetClass(), primitive->GetClass()->GetClass()); |
| 36 | EXPECT_TRUE(primitive->GetClass()->GetSuperClass() != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 37 | ASSERT_TRUE(primitive->GetDescriptor()->Equals(descriptor)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 38 | EXPECT_TRUE(primitive->GetSuperClass() == NULL); |
| 39 | EXPECT_FALSE(primitive->HasSuperClass()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 40 | EXPECT_TRUE(primitive->GetClassLoader() == NULL); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 41 | EXPECT_EQ(Class::kStatusInitialized, primitive->GetStatus()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 42 | EXPECT_FALSE(primitive->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 43 | EXPECT_TRUE(primitive->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 44 | EXPECT_TRUE(primitive->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 45 | EXPECT_TRUE(primitive->IsVerified()); |
| 46 | EXPECT_TRUE(primitive->IsInitialized()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 47 | EXPECT_FALSE(primitive->IsArrayInstance()); |
| 48 | EXPECT_FALSE(primitive->IsArrayClass()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 49 | EXPECT_TRUE(primitive->GetComponentType() == NULL); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 50 | EXPECT_FALSE(primitive->IsInterface()); |
| 51 | EXPECT_TRUE(primitive->IsPublic()); |
| 52 | EXPECT_TRUE(primitive->IsFinal()); |
| 53 | EXPECT_TRUE(primitive->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 54 | EXPECT_FALSE(primitive->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 55 | EXPECT_EQ(0U, primitive->NumDirectMethods()); |
| 56 | EXPECT_EQ(0U, primitive->NumVirtualMethods()); |
| 57 | EXPECT_EQ(0U, primitive->NumInstanceFields()); |
| 58 | EXPECT_EQ(0U, primitive->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 59 | EXPECT_EQ(0U, primitive->NumInterfaces()); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 60 | EXPECT_TRUE(primitive->GetVTable() == NULL); |
| 61 | EXPECT_EQ(0, primitive->GetIfTableCount()); |
| 62 | EXPECT_TRUE(primitive->GetIfTable() == NULL); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 65 | void AssertArrayClass(const std::string& array_descriptor, |
| 66 | const std::string& component_type, |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 67 | const ClassLoader* class_loader) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 68 | Class* array = class_linker_->FindClass(array_descriptor, class_loader); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 69 | EXPECT_TRUE(array->GetComponentType()->GetDescriptor()->Equals(component_type)); |
| 70 | EXPECT_EQ(class_loader, array->GetClassLoader()); |
| 71 | AssertArrayClass(array_descriptor, array); |
| 72 | } |
| 73 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 74 | void AssertArrayClass(const std::string& array_descriptor, Class* array) { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 75 | ASSERT_TRUE(array != NULL); |
| 76 | ASSERT_TRUE(array->GetClass() != NULL); |
| 77 | ASSERT_EQ(array->GetClass(), array->GetClass()->GetClass()); |
| 78 | EXPECT_TRUE(array->GetClass()->GetSuperClass() != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 79 | ASSERT_TRUE(array->GetDescriptor()->Equals(array_descriptor)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 80 | EXPECT_TRUE(array->GetSuperClass() != NULL); |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 81 | EXPECT_EQ(class_linker_->FindSystemClass("Ljava/lang/Object;"), array->GetSuperClass()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 82 | EXPECT_TRUE(array->HasSuperClass()); |
| 83 | ASSERT_TRUE(array->GetComponentType() != NULL); |
| 84 | ASSERT_TRUE(array->GetComponentType()->GetDescriptor() != NULL); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 85 | EXPECT_EQ(Class::kStatusInitialized, array->GetStatus()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 86 | EXPECT_FALSE(array->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 87 | EXPECT_TRUE(array->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 88 | EXPECT_TRUE(array->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 89 | EXPECT_TRUE(array->IsVerified()); |
| 90 | EXPECT_TRUE(array->IsInitialized()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 91 | EXPECT_FALSE(array->IsArrayInstance()); |
| 92 | EXPECT_TRUE(array->IsArrayClass()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 93 | EXPECT_FALSE(array->IsInterface()); |
| 94 | EXPECT_EQ(array->GetComponentType()->IsPublic(), array->IsPublic()); |
| 95 | EXPECT_TRUE(array->IsFinal()); |
| 96 | EXPECT_FALSE(array->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 97 | EXPECT_FALSE(array->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 98 | EXPECT_EQ(0U, array->NumDirectMethods()); |
| 99 | EXPECT_EQ(0U, array->NumVirtualMethods()); |
| 100 | EXPECT_EQ(0U, array->NumInstanceFields()); |
| 101 | EXPECT_EQ(0U, array->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 102 | EXPECT_EQ(2U, array->NumInterfaces()); |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 103 | EXPECT_TRUE(array->GetVTable() != NULL); |
| 104 | EXPECT_EQ(2, array->GetIfTableCount()); |
| 105 | ObjectArray<InterfaceEntry>* iftable = array->GetIfTable(); |
| 106 | ASSERT_TRUE(iftable != NULL); |
| 107 | EXPECT_TRUE(iftable->Get(0)->GetInterface()->GetDescriptor()->Equals("Ljava/lang/Cloneable;")); |
| 108 | EXPECT_TRUE(iftable->Get(1)->GetInterface()->GetDescriptor()->Equals("Ljava/io/Serializable;")); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 109 | } |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 110 | |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 111 | void AssertMethod(Class* klass, Method* method) { |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 112 | EXPECT_TRUE(method != NULL); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 113 | EXPECT_TRUE(method->GetClass() != NULL); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 114 | EXPECT_TRUE(method->GetName() != NULL); |
| 115 | EXPECT_TRUE(method->GetSignature() != NULL); |
| 116 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 117 | EXPECT_TRUE(method->GetDexCacheStrings() != NULL); |
| 118 | EXPECT_TRUE(method->GetDexCacheResolvedTypes() != NULL); |
| 119 | EXPECT_TRUE(method->GetDexCacheResolvedMethods() != NULL); |
| 120 | EXPECT_TRUE(method->GetDexCacheResolvedFields() != NULL); |
| 121 | EXPECT_TRUE(method->GetDexCacheCodeAndDirectMethods() != NULL); |
| 122 | EXPECT_TRUE(method->GetDexCacheInitializedStaticStorage() != NULL); |
| 123 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetStrings(), |
| 124 | method->GetDexCacheStrings()); |
| 125 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetResolvedTypes(), |
| 126 | method->GetDexCacheResolvedTypes()); |
| 127 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetResolvedMethods(), |
| 128 | method->GetDexCacheResolvedMethods()); |
| 129 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetResolvedFields(), |
| 130 | method->GetDexCacheResolvedFields()); |
| 131 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetCodeAndDirectMethods(), |
| 132 | method->GetDexCacheCodeAndDirectMethods()); |
| 133 | EXPECT_EQ(method->GetDeclaringClass()->GetDexCache()->GetInitializedStaticStorage(), |
| 134 | method->GetDexCacheInitializedStaticStorage()); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 137 | void AssertField(Class* klass, Field* field) { |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 138 | EXPECT_TRUE(field != NULL); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 139 | EXPECT_TRUE(field->GetClass() != NULL); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 140 | EXPECT_EQ(klass, field->GetDeclaringClass()); |
| 141 | EXPECT_TRUE(field->GetName() != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 142 | EXPECT_TRUE(field->GetType() != NULL); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 145 | void AssertClass(const std::string& descriptor, Class* klass) { |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 146 | EXPECT_TRUE(klass->GetDescriptor()->Equals(descriptor)); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 147 | SirtRef<String> Object_descriptor(String::AllocFromModifiedUtf8("Ljava/lang/Object;")); |
| 148 | if (klass->GetDescriptor()->Equals(Object_descriptor.get())) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 149 | EXPECT_FALSE(klass->HasSuperClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 150 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 151 | EXPECT_TRUE(klass->HasSuperClass()); |
| 152 | EXPECT_TRUE(klass->GetSuperClass() != NULL); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 153 | } |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 154 | EXPECT_TRUE(klass->GetClass() != NULL); |
| 155 | EXPECT_EQ(klass->GetClass(), klass->GetClass()->GetClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 156 | EXPECT_TRUE(klass->GetDexCache() != NULL); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 157 | EXPECT_TRUE(klass->IsLoaded()); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 158 | EXPECT_TRUE(klass->IsResolved()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 159 | EXPECT_FALSE(klass->IsErroneous()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 160 | EXPECT_FALSE(klass->IsArrayClass()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 161 | EXPECT_TRUE(klass->GetComponentType() == NULL); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 162 | EXPECT_TRUE(klass->IsInSamePackage(klass)); |
| 163 | EXPECT_TRUE(Class::IsInSamePackage(klass->GetDescriptor(), klass->GetDescriptor())); |
| 164 | if (klass->IsInterface()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 165 | EXPECT_TRUE(klass->IsAbstract()); |
| 166 | if (klass->NumDirectMethods() == 1) { |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 167 | EXPECT_TRUE(klass->GetDirectMethod(0)->IsClassInitializer()); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 168 | EXPECT_TRUE(klass->GetDirectMethod(0)->IsDirect()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 169 | } else { |
| 170 | EXPECT_EQ(0U, klass->NumDirectMethods()); |
| 171 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 172 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 173 | if (!klass->IsSynthetic()) { |
| 174 | EXPECT_NE(0U, klass->NumDirectMethods()); |
| 175 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 176 | } |
Brian Carlstrom | 8692721 | 2011-09-15 11:31:11 -0700 | [diff] [blame] | 177 | EXPECT_EQ(klass->IsInterface(), klass->GetVTable() == NULL); |
| 178 | for (int i = 0; i < klass->GetIfTableCount(); i++) { |
| 179 | const InterfaceEntry* interface_entry = klass->GetIfTable()->Get(i); |
| 180 | ASSERT_TRUE(interface_entry != NULL); |
| 181 | Class* interface = interface_entry->GetInterface(); |
| 182 | ASSERT_TRUE(interface != NULL); |
| 183 | EXPECT_TRUE(interface_entry->GetInterface() != NULL); |
| 184 | if (klass->IsInterface()) { |
| 185 | EXPECT_EQ(0U, interface_entry->GetMethodArrayCount()); |
| 186 | } else { |
| 187 | CHECK_EQ(interface->NumVirtualMethods(), interface_entry->GetMethodArrayCount()); |
| 188 | EXPECT_EQ(interface->NumVirtualMethods(), interface_entry->GetMethodArrayCount()); |
| 189 | } |
| 190 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 191 | if (klass->IsAbstract()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 192 | EXPECT_FALSE(klass->IsFinal()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 193 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 194 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 195 | } |
| 196 | if (klass->IsFinal()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 197 | EXPECT_FALSE(klass->IsAbstract()); |
| 198 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 199 | } |
| 200 | if (klass->IsAnnotation()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 201 | EXPECT_FALSE(klass->IsFinal()); |
| 202 | EXPECT_TRUE(klass->IsAbstract()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | EXPECT_FALSE(klass->IsPrimitive()); |
| 206 | EXPECT_TRUE(klass->CanAccess(klass)); |
| 207 | |
| 208 | for (size_t i = 0; i < klass->NumDirectMethods(); i++) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 209 | Method* method = klass->GetDirectMethod(i); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 210 | AssertMethod(klass, method); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(method->IsDirect()); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 212 | EXPECT_EQ(klass, method->GetDeclaringClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | for (size_t i = 0; i < klass->NumVirtualMethods(); i++) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 216 | Method* method = klass->GetVirtualMethod(i); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 217 | AssertMethod(klass, method); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 218 | EXPECT_FALSE(method->IsDirect()); |
Brian Carlstrom | c4fa2c0 | 2011-08-21 03:00:12 -0700 | [diff] [blame] | 219 | EXPECT_TRUE(method->GetDeclaringClass()->IsAssignableFrom(klass)); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | for (size_t i = 0; i < klass->NumInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 223 | Field* field = klass->GetInstanceField(i); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 224 | AssertField(klass, field); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 225 | EXPECT_FALSE(field->IsStatic()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | for (size_t i = 0; i < klass->NumStaticFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 229 | Field* field = klass->GetStaticField(i); |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 230 | AssertField(klass, field); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 231 | EXPECT_TRUE(field->IsStatic()); |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 232 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 233 | |
| 234 | // Confirm that all instances fields are packed together at the start |
| 235 | EXPECT_GE(klass->NumInstanceFields(), klass->NumReferenceInstanceFields()); |
| 236 | for (size_t i = 0; i < klass->NumReferenceInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 237 | Field* field = klass->GetInstanceField(i); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 238 | Class* field_type = field->GetType(); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 239 | ASSERT_TRUE(field_type != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 240 | ASSERT_TRUE(!field_type->IsPrimitive()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 241 | } |
| 242 | for (size_t i = klass->NumReferenceInstanceFields(); i < klass->NumInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 243 | Field* field = klass->GetInstanceField(i); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 244 | Class* field_type = field->GetType(); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 245 | ASSERT_TRUE(field_type != NULL); |
Brian Carlstrom | fbfdce6 | 2011-10-05 17:33:32 -0700 | [diff] [blame] | 246 | if (!field_type->IsPrimitive()) { |
| 247 | // While Reference.referent is not primitive, the ClassLinker |
| 248 | // treats it as such so that the garbage collector won't scan it. |
| 249 | EXPECT_EQ(PrettyField(field), "java.lang.Object java.lang.ref.Reference.referent"); |
| 250 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | size_t total_num_reference_instance_fields = 0; |
| 254 | Class* k = klass; |
| 255 | while (k != NULL) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 256 | total_num_reference_instance_fields += k->NumReferenceInstanceFields(); |
| 257 | k = k->GetSuperClass(); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 258 | } |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 259 | EXPECT_EQ(klass->GetReferenceInstanceOffsets() == 0, |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 260 | total_num_reference_instance_fields == 0); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 263 | void AssertDexFileClass(ClassLoader* class_loader, const std::string& descriptor) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 264 | ASSERT_TRUE(descriptor != NULL); |
| 265 | Class* klass = class_linker_->FindSystemClass(descriptor); |
| 266 | ASSERT_TRUE(klass != NULL); |
| 267 | EXPECT_TRUE(klass->GetDescriptor()->Equals(descriptor)); |
| 268 | EXPECT_EQ(class_loader, klass->GetClassLoader()); |
| 269 | if (klass->IsPrimitive()) { |
| 270 | AssertPrimitiveClass(descriptor, klass); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 271 | } else if (klass->IsArrayClass()) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 272 | AssertArrayClass(descriptor, klass); |
| 273 | } else { |
| 274 | AssertClass(descriptor, klass); |
| 275 | } |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 278 | void AssertDexFile(const DexFile* dex, ClassLoader* class_loader) { |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 279 | ASSERT_TRUE(dex != NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 280 | |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 281 | // Verify all the classes defined in this file |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 282 | for (size_t i = 0; i < dex->NumClassDefs(); i++) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 283 | const DexFile::ClassDef& class_def = dex->GetClassDef(i); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 284 | const char* descriptor = dex->GetClassDescriptor(class_def); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 285 | AssertDexFileClass(class_loader, descriptor); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 286 | } |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 287 | // Verify all the types referenced by this file |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 288 | for (size_t i = 0; i < dex->NumTypeIds(); i++) { |
| 289 | const DexFile::TypeId& type_id = dex->GetTypeId(i); |
| 290 | const char* descriptor = dex->GetTypeDescriptor(type_id); |
| 291 | AssertDexFileClass(class_loader, descriptor); |
| 292 | } |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 293 | class_linker_->VisitRoots(TestRootVisitor, NULL); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 294 | } |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 295 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 296 | static void TestRootVisitor(const Object* root, void* arg) { |
Brian Carlstrom | d2fbb2b | 2011-08-23 11:57:08 -0700 | [diff] [blame] | 297 | EXPECT_TRUE(root != NULL); |
| 298 | } |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 299 | }; |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 300 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 301 | struct CheckOffset { |
| 302 | size_t cpp_offset; |
| 303 | const char* java_name; |
| 304 | CheckOffset(size_t c, const char* j) : cpp_offset(c), java_name(j) {} |
| 305 | }; |
| 306 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 307 | template <typename T> |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 308 | struct CheckOffsets { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 309 | CheckOffsets(bool is_static, const char* class_descriptor) |
| 310 | : is_static(is_static), class_descriptor(class_descriptor) {} |
| 311 | bool is_static; |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 312 | std::string class_descriptor; |
| 313 | std::vector<CheckOffset> offsets; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 314 | |
| 315 | bool Check() { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 316 | Class* klass = Runtime::Current()->GetClassLinker()->FindSystemClass(class_descriptor); |
| 317 | CHECK(klass != NULL) << class_descriptor; |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 318 | |
| 319 | bool error = false; |
| 320 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 321 | if (!klass->IsClassClass() && !is_static) { |
| 322 | size_t expected_size = is_static ? klass->GetClassSize(): klass->GetObjectSize(); |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 323 | if (sizeof(T) != expected_size) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 324 | LG << "Class size mismatch:" |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 325 | << " class=" << class_descriptor |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 326 | << " Java=" << expected_size |
| 327 | << " C++=" << sizeof(T); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 328 | error = true; |
| 329 | } |
| 330 | } |
| 331 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 332 | size_t num_fields = is_static ? klass->NumStaticFields() : klass->NumInstanceFields(); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 333 | if (offsets.size() != num_fields) { |
| 334 | LG << "Field count mismatch:" |
| 335 | << " class=" << class_descriptor |
| 336 | << " Java=" << num_fields |
| 337 | << " C++=" << offsets.size(); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 338 | error = true; |
| 339 | } |
| 340 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 341 | for (size_t i = 0; i < offsets.size(); i++) { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 342 | Field* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 343 | if (!field->GetName()->Equals(offsets[i].java_name)) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 344 | error = true; |
| 345 | } |
| 346 | } |
| 347 | if (error) { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 348 | for (size_t i = 0; i < offsets.size(); i++) { |
| 349 | CheckOffset& offset = offsets[i]; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 350 | Field* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 351 | if (!field->GetName()->Equals(offsets[i].java_name)) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 352 | LG << "JAVA FIELD ORDER MISMATCH NEXT LINE:"; |
| 353 | } |
| 354 | LG << "Java field order:" |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 355 | << " i=" << i << " class=" << class_descriptor |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 356 | << " Java=" << field->GetName()->ToModifiedUtf8() |
| 357 | << " CheckOffsets=" << offset.java_name; |
| 358 | } |
| 359 | } |
| 360 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 361 | for (size_t i = 0; i < offsets.size(); i++) { |
| 362 | CheckOffset& offset = offsets[i]; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 363 | Field* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 364 | if (field->GetOffset().Uint32Value() != offset.cpp_offset) { |
| 365 | error = true; |
| 366 | } |
| 367 | } |
| 368 | if (error) { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 369 | for (size_t i = 0; i < offsets.size(); i++) { |
| 370 | CheckOffset& offset = offsets[i]; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 371 | Field* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 372 | if (field->GetOffset().Uint32Value() != offset.cpp_offset) { |
| 373 | LG << "OFFSET MISMATCH NEXT LINE:"; |
| 374 | } |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 375 | LG << "Offset: class=" << class_descriptor << " field=" << offset.java_name |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 376 | << " Java=" << field->GetOffset().Uint32Value() << " C++=" << offset.cpp_offset; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return !error; |
| 381 | }; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 382 | |
| 383 | private: |
| 384 | DISALLOW_IMPLICIT_CONSTRUCTORS(CheckOffsets); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 387 | // Note that ClassLinkerTest.ValidateFieldOrderOfJavaCppUnionClasses |
| 388 | // is first since if it is failing, others are unlikely to succeed. |
| 389 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 390 | struct ObjectOffsets : public CheckOffsets<Object> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 391 | ObjectOffsets() : CheckOffsets<Object>(false, "Ljava/lang/Object;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 392 | // alphabetical references |
| 393 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Object, klass_), "shadow$_klass_")); |
| 394 | |
| 395 | // alphabetical 32-bit |
| 396 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Object, monitor_), "shadow$_monitor_")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 397 | }; |
| 398 | }; |
| 399 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 400 | struct AccessibleObjectOffsets : public CheckOffsets<AccessibleObject> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 401 | AccessibleObjectOffsets() |
| 402 | : CheckOffsets<AccessibleObject>(false, "Ljava/lang/reflect/AccessibleObject;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 403 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(AccessibleObject, java_flag_), "flag")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 404 | }; |
| 405 | }; |
| 406 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 407 | struct FieldOffsets : public CheckOffsets<Field> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 408 | FieldOffsets() : CheckOffsets<Field>(false, "Ljava/lang/reflect/Field;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 409 | // alphabetical references |
| 410 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, declaring_class_), "declaringClass")); |
| 411 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, generic_type_), "genericType")); |
| 412 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, name_), "name")); |
| 413 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, type_), "type")); |
| 414 | |
| 415 | // alphabetical 32-bit |
| 416 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, generic_types_are_initialized_), "genericTypesAreInitialized")); |
| 417 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, access_flags_), "shadow$_access_flags_")); |
| 418 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, offset_), "shadow$_offset_")); |
| 419 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, type_idx_), "shadow$_type_idx_")); |
| 420 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Field, slot_), "slot")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 421 | }; |
| 422 | }; |
| 423 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 424 | struct MethodOffsets : public CheckOffsets<Method> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 425 | MethodOffsets() : CheckOffsets<Method>(false, "Ljava/lang/reflect/Method;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 426 | // alphabetical references |
| 427 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, declaring_class_), "declaringClass")); |
| 428 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_exception_types_), "exceptionTypes")); |
| 429 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_formal_type_parameters_), "formalTypeParameters")); |
| 430 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_generic_exception_types_), "genericExceptionTypes")); |
| 431 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_generic_parameter_types_), "genericParameterTypes")); |
| 432 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_generic_return_type_), "genericReturnType")); |
| 433 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, name_), "name")); |
| 434 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_parameter_types_), "parameterTypes")); |
| 435 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_return_type_), "returnType")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 436 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_code_and_direct_methods_), "shadow$_dex_cache_code_and_direct_methods_")); |
| 437 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_initialized_static_storage_), "shadow$_dex_cache_initialized_static_storage_")); |
| 438 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_resolved_fields_), "shadow$_dex_cache_resolved_fields_")); |
| 439 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_resolved_methods_), "shadow$_dex_cache_resolved_methods_")); |
| 440 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_resolved_types_), "shadow$_dex_cache_resolved_types_")); |
| 441 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, dex_cache_strings_), "shadow$_dex_cache_strings_")); |
jeffhao | e23d93c | 2011-09-15 14:48:43 -0700 | [diff] [blame] | 442 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, register_map_data_), "shadow$_register_map_data_")); |
| 443 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, register_map_header_), "shadow$_register_map_header_")); |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 444 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, shorty_), "shadow$_shorty_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 445 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, signature_), "shadow$_signature_")); |
| 446 | |
| 447 | // alphabetical 32-bit |
| 448 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_generic_types_are_initialized_), "genericTypesAreInitialized")); |
| 449 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, access_flags_), "shadow$_access_flags_")); |
| 450 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, code_), "shadow$_code_")); |
| 451 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, code_item_offset_), "shadow$_code_item_offset_")); |
| 452 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, core_spill_mask_), "shadow$_core_spill_mask_")); |
| 453 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, fp_spill_mask_), "shadow$_fp_spill_mask_")); |
| 454 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, frame_size_in_bytes_), "shadow$_frame_size_in_bytes_")); |
| 455 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, invoke_stub_), "shadow$_invoke_stub_")); |
| 456 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_return_type_idx_), "shadow$_java_return_type_idx_")); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 457 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, mapping_table_), "shadow$_mapping_table_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 458 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, method_index_), "shadow$_method_index_")); |
| 459 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, native_method_), "shadow$_native_method_")); |
| 460 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, num_ins_), "shadow$_num_ins_")); |
| 461 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, num_outs_), "shadow$_num_outs_")); |
| 462 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, num_registers_), "shadow$_num_registers_")); |
| 463 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, proto_idx_), "shadow$_proto_idx_")); |
| 464 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, return_pc_offset_in_bytes_), "shadow$_return_pc_offset_in_bytes_")); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 465 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, vmap_table_), "shadow$_vmap_table_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 466 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Method, java_slot_), "slot")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 467 | }; |
| 468 | }; |
| 469 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 470 | struct ConstructorOffsets : public MethodOffsets { |
| 471 | ConstructorOffsets() : MethodOffsets() { |
| 472 | // We use Method* for both java.lang.reflect.Constructor and java.lang.reflect.Method. |
| 473 | class_descriptor = "Ljava/lang/reflect/Constructor;"; |
| 474 | } |
| 475 | }; |
| 476 | |
| 477 | struct ClassOffsets : public CheckOffsets<Class> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 478 | ClassOffsets() : CheckOffsets<Class>(false, "Ljava/lang/Class;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 479 | // alphabetical references |
| 480 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, name_), "name")); |
| 481 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, class_loader_), "shadow$_class_loader_")); |
| 482 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, component_type_), "shadow$_component_type_")); |
| 483 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, descriptor_), "shadow$_descriptor_")); |
| 484 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, dex_cache_), "shadow$_dex_cache_")); |
| 485 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, direct_methods_), "shadow$_direct_methods_")); |
| 486 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, ifields_), "shadow$_ifields_")); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 487 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, iftable_), "shadow$_iftable_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 488 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, interfaces_), "shadow$_interfaces_")); |
| 489 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, interfaces_type_idx_), "shadow$_interfaces_type_idx_")); |
| 490 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, sfields_), "shadow$_sfields_")); |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 491 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, source_file_), "shadow$_source_file_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 492 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, super_class_), "shadow$_super_class_")); |
| 493 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, verify_error_class_), "shadow$_verify_error_class_")); |
| 494 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, virtual_methods_), "shadow$_virtual_methods_")); |
| 495 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, vtable_), "shadow$_vtable_")); |
| 496 | |
| 497 | // alphabetical 32-bit |
| 498 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, access_flags_), "shadow$_access_flags_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 499 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, class_size_), "shadow$_class_size_")); |
| 500 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, clinit_thread_id_), "shadow$_clinit_thread_id_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 501 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, num_reference_instance_fields_), "shadow$_num_reference_instance_fields_")); |
| 502 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, num_reference_static_fields_), "shadow$_num_reference_static_fields_")); |
| 503 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, object_size_), "shadow$_object_size_")); |
| 504 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, primitive_type_), "shadow$_primitive_type_")); |
| 505 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, reference_instance_offsets_), "shadow$_reference_instance_offsets_")); |
| 506 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, reference_static_offsets_), "shadow$_reference_static_offsets_")); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 507 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, status_), "shadow$_status_")); |
| 508 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Class, super_class_type_idx_), "shadow$_super_class_type_idx_")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 509 | }; |
| 510 | }; |
| 511 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 512 | struct StringOffsets : public CheckOffsets<String> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 513 | StringOffsets() : CheckOffsets<String>(false, "Ljava/lang/String;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 514 | // alphabetical references |
| 515 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(String, array_), "value")); |
| 516 | |
| 517 | // alphabetical 32-bit |
| 518 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(String, count_), "count")); |
| 519 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(String, hash_code_), "hashCode")); |
| 520 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(String, offset_), "offset")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 521 | }; |
| 522 | }; |
| 523 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 524 | struct ThrowableOffsets : public CheckOffsets<Throwable> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 525 | ThrowableOffsets() : CheckOffsets<Throwable>(false, "Ljava/lang/Throwable;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 526 | // alphabetical references |
| 527 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Throwable, cause_), "cause")); |
| 528 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Throwable, detail_message_), "detailMessage")); |
| 529 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Throwable, stack_state_), "stackState")); |
| 530 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Throwable, stack_trace_), "stackTrace")); |
| 531 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Throwable, suppressed_exceptions_), "suppressedExceptions")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 532 | }; |
| 533 | }; |
| 534 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 535 | struct StackTraceElementOffsets : public CheckOffsets<StackTraceElement> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 536 | StackTraceElementOffsets() : CheckOffsets<StackTraceElement>(false, "Ljava/lang/StackTraceElement;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 537 | // alphabetical references |
| 538 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StackTraceElement, declaring_class_), "declaringClass")); |
| 539 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StackTraceElement, file_name_), "fileName")); |
| 540 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StackTraceElement, method_name_), "methodName")); |
| 541 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StackTraceElement, line_number_), "lineNumber")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 542 | }; |
| 543 | }; |
| 544 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 545 | struct ClassLoaderOffsets : public CheckOffsets<ClassLoader> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 546 | ClassLoaderOffsets() : CheckOffsets<ClassLoader>(false, "Ljava/lang/ClassLoader;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 547 | // alphabetical references |
| 548 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ClassLoader, packages_), "packages")); |
| 549 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ClassLoader, parent_), "parent")); |
Jesse Wilson | 1b5f497 | 2011-10-11 21:41:08 -0400 | [diff] [blame] | 550 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ClassLoader, proxyCache_), "proxyCache")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 551 | }; |
| 552 | }; |
| 553 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 554 | struct BaseDexClassLoaderOffsets : public CheckOffsets<BaseDexClassLoader> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 555 | BaseDexClassLoaderOffsets() |
| 556 | : CheckOffsets<BaseDexClassLoader>(false, "Ldalvik/system/BaseDexClassLoader;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 557 | // alphabetical references |
| 558 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(BaseDexClassLoader, original_path_), "originalPath")); |
| 559 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(BaseDexClassLoader, path_list_), "pathList")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 560 | }; |
| 561 | }; |
| 562 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 563 | struct PathClassLoaderOffsets : public CheckOffsets<PathClassLoader> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 564 | PathClassLoaderOffsets() |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 565 | : CheckOffsets<PathClassLoader>(false, "Ldalvik/system/PathClassLoader;") {} |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 566 | }; |
| 567 | |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 568 | struct ProxyOffsets : public CheckOffsets<Proxy> { |
| 569 | ProxyOffsets() : CheckOffsets<Proxy>(false, "Ljava/lang/reflect/Proxy;") { |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 570 | // alphabetical references |
| 571 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(Proxy, h_), "h")); |
| 572 | }; |
| 573 | }; |
| 574 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 575 | struct ClassClassOffsets : public CheckOffsets<ClassClass> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 576 | ClassClassOffsets() : CheckOffsets<ClassClass>(true, "Ljava/lang/Class;") { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 577 | // padding 32-bit |
| 578 | CHECK_EQ(OFFSETOF_MEMBER(ClassClass, padding_) + 4, |
| 579 | OFFSETOF_MEMBER(ClassClass, serialVersionUID_)); |
| 580 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 581 | // alphabetical 64-bit |
| 582 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ClassClass, serialVersionUID_), "serialVersionUID")); |
| 583 | }; |
| 584 | }; |
| 585 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 586 | struct StringClassOffsets : public CheckOffsets<StringClass> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 587 | StringClassOffsets() : CheckOffsets<StringClass>(true, "Ljava/lang/String;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 588 | // alphabetical references |
| 589 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StringClass, ASCII_), "ASCII")); |
| 590 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StringClass, CASE_INSENSITIVE_ORDER_), "CASE_INSENSITIVE_ORDER")); |
| 591 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 592 | // padding 32-bit |
| 593 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StringClass, REPLACEMENT_CHAR_), "REPLACEMENT_CHAR")); |
| 594 | |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 595 | // alphabetical 64-bit |
| 596 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(StringClass, serialVersionUID_), "serialVersionUID")); |
| 597 | }; |
| 598 | }; |
| 599 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 600 | struct FieldClassOffsets : public CheckOffsets<FieldClass> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 601 | FieldClassOffsets() : CheckOffsets<FieldClass>(true, "Ljava/lang/reflect/Field;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 602 | // alphabetical references |
| 603 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, ORDER_BY_NAME_AND_DECLARING_CLASS_), "ORDER_BY_NAME_AND_DECLARING_CLASS")); |
| 604 | |
| 605 | // alphabetical 32-bit |
| 606 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_BOOLEAN_), "TYPE_BOOLEAN")); |
| 607 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_BYTE_), "TYPE_BYTE")); |
| 608 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_CHAR_), "TYPE_CHAR")); |
| 609 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_DOUBLE_), "TYPE_DOUBLE")); |
| 610 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_FLOAT_), "TYPE_FLOAT")); |
| 611 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_INTEGER_), "TYPE_INTEGER")); |
| 612 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_LONG_), "TYPE_LONG")); |
| 613 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(FieldClass, TYPE_SHORT_), "TYPE_SHORT")); |
| 614 | }; |
| 615 | }; |
| 616 | |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 617 | struct MethodClassOffsets : public CheckOffsets<MethodClass> { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 618 | MethodClassOffsets() : CheckOffsets<MethodClass>(true, "Ljava/lang/reflect/Method;") { |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 619 | // alphabetical references |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 620 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(MethodClass, ORDER_BY_SIGNATURE_), "ORDER_BY_SIGNATURE")); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 621 | }; |
| 622 | }; |
| 623 | |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 624 | struct ProxyClassOffsets : public CheckOffsets<ProxyClass> { |
| 625 | ProxyClassOffsets() : CheckOffsets<ProxyClass>(true, "Ljava/lang/reflect/Proxy;") { |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 626 | // alphabetical 32-bit |
| 627 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ProxyClass, NextClassNameIndex_), "NextClassNameIndex")); |
| 628 | |
| 629 | // alphabetical 64-bit |
| 630 | offsets.push_back(CheckOffset(OFFSETOF_MEMBER(ProxyClass, serialVersionUID_), "serialVersionUID")); |
| 631 | }; |
| 632 | }; |
| 633 | |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 634 | // 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] | 635 | // 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] | 636 | // ClassLinker::LinkFields. |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 637 | TEST_F(ClassLinkerTest, ValidateFieldOrderOfJavaCppUnionClasses) { |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 638 | EXPECT_TRUE(ObjectOffsets().Check()); |
| 639 | EXPECT_TRUE(AccessibleObjectOffsets().Check()); |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 640 | EXPECT_TRUE(ConstructorOffsets().Check()); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 641 | EXPECT_TRUE(FieldOffsets().Check()); |
| 642 | EXPECT_TRUE(MethodOffsets().Check()); |
| 643 | EXPECT_TRUE(ClassOffsets().Check()); |
| 644 | EXPECT_TRUE(StringOffsets().Check()); |
| 645 | EXPECT_TRUE(ThrowableOffsets().Check()); |
| 646 | EXPECT_TRUE(StackTraceElementOffsets().Check()); |
| 647 | EXPECT_TRUE(ClassLoaderOffsets().Check()); |
| 648 | EXPECT_TRUE(BaseDexClassLoaderOffsets().Check()); |
| 649 | EXPECT_TRUE(PathClassLoaderOffsets().Check()); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 650 | EXPECT_TRUE(ProxyOffsets().Check()); |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 651 | |
| 652 | EXPECT_TRUE(ClassClassOffsets().Check()); |
| 653 | EXPECT_TRUE(StringClassOffsets().Check()); |
| 654 | EXPECT_TRUE(FieldClassOffsets().Check()); |
| 655 | EXPECT_TRUE(MethodClassOffsets().Check()); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 656 | EXPECT_TRUE(ProxyClassOffsets().Check()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 659 | TEST_F(ClassLinkerTest, FindClassNonexistent) { |
| 660 | AssertNonExistentClass("NoSuchClass;"); |
| 661 | AssertNonExistentClass("LNoSuchClass;"); |
| 662 | } |
| 663 | |
| 664 | TEST_F(ClassLinkerTest, FindClassNested) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 665 | SirtRef<ClassLoader> class_loader(LoadDex("Nested")); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 666 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 667 | Class* outer = class_linker_->FindClass("LNested;", class_loader.get()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 668 | ASSERT_TRUE(outer != NULL); |
| 669 | EXPECT_EQ(0U, outer->NumVirtualMethods()); |
| 670 | EXPECT_EQ(1U, outer->NumDirectMethods()); |
| 671 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 672 | Class* inner = class_linker_->FindClass("LNested$Inner;", class_loader.get()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 673 | ASSERT_TRUE(inner != NULL); |
| 674 | EXPECT_EQ(0U, inner->NumVirtualMethods()); |
| 675 | EXPECT_EQ(1U, inner->NumDirectMethods()); |
| 676 | } |
| 677 | |
| 678 | TEST_F(ClassLinkerTest, FindClass_Primitives) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 679 | const std::string expected("BCDFIJSZV"); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 680 | for (int ch = 0; ch < 255; ch++) { |
| 681 | char* s = reinterpret_cast<char*>(&ch); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 682 | const std::string descriptor(s, 1); |
| 683 | if (expected.find(ch) == std::string::npos) { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 684 | AssertNonExistentClass(descriptor); |
| 685 | } else { |
| 686 | AssertPrimitiveClass(descriptor); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | TEST_F(ClassLinkerTest, FindClass) { |
| 692 | Class* JavaLangObject = class_linker_->FindSystemClass("Ljava/lang/Object;"); |
| 693 | ASSERT_TRUE(JavaLangObject != NULL); |
| 694 | ASSERT_TRUE(JavaLangObject->GetClass() != NULL); |
| 695 | ASSERT_EQ(JavaLangObject->GetClass(), JavaLangObject->GetClass()->GetClass()); |
| 696 | EXPECT_EQ(JavaLangObject, JavaLangObject->GetClass()->GetSuperClass()); |
| 697 | ASSERT_TRUE(JavaLangObject->GetDescriptor()->Equals("Ljava/lang/Object;")); |
| 698 | EXPECT_TRUE(JavaLangObject->GetSuperClass() == NULL); |
| 699 | EXPECT_FALSE(JavaLangObject->HasSuperClass()); |
| 700 | EXPECT_TRUE(JavaLangObject->GetClassLoader() == NULL); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 701 | EXPECT_EQ(Class::kStatusResolved, JavaLangObject->GetStatus()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 702 | EXPECT_FALSE(JavaLangObject->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 703 | EXPECT_TRUE(JavaLangObject->IsLoaded()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 704 | EXPECT_TRUE(JavaLangObject->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 705 | EXPECT_FALSE(JavaLangObject->IsVerified()); |
| 706 | EXPECT_FALSE(JavaLangObject->IsInitialized()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 707 | EXPECT_FALSE(JavaLangObject->IsArrayInstance()); |
| 708 | EXPECT_FALSE(JavaLangObject->IsArrayClass()); |
| 709 | EXPECT_TRUE(JavaLangObject->GetComponentType() == NULL); |
| 710 | EXPECT_FALSE(JavaLangObject->IsInterface()); |
| 711 | EXPECT_TRUE(JavaLangObject->IsPublic()); |
| 712 | EXPECT_FALSE(JavaLangObject->IsFinal()); |
| 713 | EXPECT_FALSE(JavaLangObject->IsPrimitive()); |
| 714 | EXPECT_FALSE(JavaLangObject->IsSynthetic()); |
| 715 | EXPECT_EQ(2U, JavaLangObject->NumDirectMethods()); |
| 716 | EXPECT_EQ(11U, JavaLangObject->NumVirtualMethods()); |
| 717 | EXPECT_EQ(2U, JavaLangObject->NumInstanceFields()); |
| 718 | EXPECT_TRUE(JavaLangObject->GetInstanceField(0)->GetName()->Equals("shadow$_klass_")); |
| 719 | EXPECT_TRUE(JavaLangObject->GetInstanceField(1)->GetName()->Equals("shadow$_monitor_")); |
| 720 | |
| 721 | EXPECT_EQ(0U, JavaLangObject->NumStaticFields()); |
| 722 | EXPECT_EQ(0U, JavaLangObject->NumInterfaces()); |
| 723 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 724 | SirtRef<ClassLoader> class_loader(LoadDex("MyClass")); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 725 | AssertNonExistentClass("LMyClass;"); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 726 | Class* MyClass = class_linker_->FindClass("LMyClass;", class_loader.get()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 727 | ASSERT_TRUE(MyClass != NULL); |
| 728 | ASSERT_TRUE(MyClass->GetClass() != NULL); |
| 729 | ASSERT_EQ(MyClass->GetClass(), MyClass->GetClass()->GetClass()); |
| 730 | EXPECT_EQ(JavaLangObject, MyClass->GetClass()->GetSuperClass()); |
| 731 | ASSERT_TRUE(MyClass->GetDescriptor()->Equals("LMyClass;")); |
| 732 | EXPECT_TRUE(MyClass->GetSuperClass() == JavaLangObject); |
| 733 | EXPECT_TRUE(MyClass->HasSuperClass()); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 734 | EXPECT_EQ(class_loader.get(), MyClass->GetClassLoader()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 735 | EXPECT_EQ(Class::kStatusResolved, MyClass->GetStatus()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 736 | EXPECT_FALSE(MyClass->IsErroneous()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 737 | EXPECT_TRUE(MyClass->IsLoaded()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 738 | EXPECT_TRUE(MyClass->IsResolved()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 739 | EXPECT_FALSE(MyClass->IsVerified()); |
| 740 | EXPECT_FALSE(MyClass->IsInitialized()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 741 | EXPECT_FALSE(MyClass->IsArrayInstance()); |
| 742 | EXPECT_FALSE(MyClass->IsArrayClass()); |
| 743 | EXPECT_TRUE(MyClass->GetComponentType() == NULL); |
| 744 | EXPECT_FALSE(MyClass->IsInterface()); |
| 745 | EXPECT_FALSE(MyClass->IsPublic()); |
| 746 | EXPECT_FALSE(MyClass->IsFinal()); |
| 747 | EXPECT_FALSE(MyClass->IsPrimitive()); |
| 748 | EXPECT_FALSE(MyClass->IsSynthetic()); |
| 749 | EXPECT_EQ(1U, MyClass->NumDirectMethods()); |
| 750 | EXPECT_EQ(0U, MyClass->NumVirtualMethods()); |
| 751 | EXPECT_EQ(0U, MyClass->NumInstanceFields()); |
| 752 | EXPECT_EQ(0U, MyClass->NumStaticFields()); |
| 753 | EXPECT_EQ(0U, MyClass->NumInterfaces()); |
| 754 | |
| 755 | EXPECT_EQ(JavaLangObject->GetClass()->GetClass(), MyClass->GetClass()->GetClass()); |
| 756 | |
| 757 | // created by class_linker |
| 758 | AssertArrayClass("[C", "C", NULL); |
| 759 | AssertArrayClass("[Ljava/lang/Object;", "Ljava/lang/Object;", NULL); |
| 760 | // synthesized on the fly |
| 761 | AssertArrayClass("[[C", "[C", NULL); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 762 | AssertArrayClass("[[[LMyClass;", "[[LMyClass;", class_loader.get()); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 763 | // or not available at all |
| 764 | AssertNonExistentClass("[[[[LNonExistentClass;"); |
| 765 | } |
| 766 | |
| 767 | TEST_F(ClassLinkerTest, LibCore) { |
| 768 | AssertDexFile(java_lang_dex_file_.get(), NULL); |
| 769 | } |
| 770 | |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 771 | // The first reference array element must be a multiple of 8 bytes from the |
| 772 | // start of the object |
| 773 | TEST_F(ClassLinkerTest, ValidateObjectArrayElementsOffset) { |
| 774 | Class* array_class = class_linker_->FindSystemClass("[Ljava/lang/String;"); |
| 775 | ObjectArray<String>* array = ObjectArray<String>::Alloc(array_class, 0); |
| 776 | uint32_t array_offset = reinterpret_cast<uint32_t>(array); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 777 | uint32_t data_offset = |
| 778 | array_offset + ObjectArray<String>::DataOffset().Uint32Value(); |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 779 | EXPECT_EQ(16U, data_offset - array_offset); |
| 780 | } |
| 781 | |
| 782 | TEST_F(ClassLinkerTest, ValidatePrimitiveArrayElementsOffset) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 783 | SirtRef<LongArray> array(LongArray::Alloc(0)); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 784 | EXPECT_EQ(class_linker_->FindSystemClass("[J"), array->GetClass()); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 785 | uint32_t array_offset = reinterpret_cast<uint32_t>(array.get()); |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 786 | uint32_t data_offset = reinterpret_cast<uint32_t>(array->GetData()); |
| 787 | EXPECT_EQ(16U, data_offset - array_offset); |
| 788 | } |
| 789 | |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 790 | TEST_F(ClassLinkerTest, ValidateBoxedTypes) { |
| 791 | // Validate that the "value" field is always the 0th field in each of java.lang's box classes. |
| 792 | // This lets UnboxPrimitive avoid searching for the field by name at runtime. |
| 793 | Class* c; |
| 794 | c = class_linker_->FindClass("Ljava/lang/Boolean;", NULL); |
| 795 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 796 | c = class_linker_->FindClass("Ljava/lang/Byte;", NULL); |
| 797 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 798 | c = class_linker_->FindClass("Ljava/lang/Character;", NULL); |
| 799 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 800 | c = class_linker_->FindClass("Ljava/lang/Double;", NULL); |
| 801 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 802 | c = class_linker_->FindClass("Ljava/lang/Float;", NULL); |
| 803 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 804 | c = class_linker_->FindClass("Ljava/lang/Integer;", NULL); |
| 805 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 806 | c = class_linker_->FindClass("Ljava/lang/Long;", NULL); |
| 807 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 808 | c = class_linker_->FindClass("Ljava/lang/Short;", NULL); |
| 809 | EXPECT_EQ("value", c->GetIFields()->Get(0)->GetName()->ToModifiedUtf8()); |
| 810 | } |
| 811 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 812 | TEST_F(ClassLinkerTest, TwoClassLoadersOneClass) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 813 | SirtRef<ClassLoader> class_loader_1(LoadDex("MyClass")); |
| 814 | SirtRef<ClassLoader> class_loader_2(LoadDex("MyClass")); |
| 815 | Class* MyClass_1 = class_linker_->FindClass("LMyClass;", class_loader_1.get()); |
| 816 | Class* MyClass_2 = class_linker_->FindClass("LMyClass;", class_loader_2.get()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 817 | EXPECT_TRUE(MyClass_1 != NULL); |
| 818 | EXPECT_TRUE(MyClass_2 != NULL); |
| 819 | EXPECT_NE(MyClass_1, MyClass_2); |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 820 | } |
| 821 | |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 822 | TEST_F(ClassLinkerTest, StaticFields) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 823 | SirtRef<ClassLoader> class_loader(LoadDex("Statics")); |
| 824 | Class* statics = class_linker_->FindClass("LStatics;", class_loader.get()); |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 825 | class_linker_->EnsureInitialized(statics, true); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 826 | |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 827 | // Static final primitives that are initialized by a compile-time constant |
| 828 | // expression resolve to a copy of a constant value from the constant pool. |
| 829 | // So <clinit> should be null. |
| 830 | Method* clinit = statics->FindDirectMethod("<clinit>", "()V"); |
| 831 | EXPECT_TRUE(clinit == NULL); |
| 832 | |
| 833 | EXPECT_EQ(9U, statics->NumStaticFields()); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 834 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 835 | Field* s0 = statics->FindStaticField("s0", class_linker_->FindClass("Z", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 836 | EXPECT_TRUE(s0->GetClass()->GetDescriptor()->Equals("Ljava/lang/reflect/Field;")); |
| 837 | EXPECT_TRUE(s0->GetType()->IsPrimitiveBoolean()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 838 | EXPECT_EQ(true, s0->GetBoolean(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 839 | s0->SetBoolean(NULL, false); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 840 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 841 | Field* s1 = statics->FindStaticField("s1", class_linker_->FindClass("B", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 842 | EXPECT_TRUE(s1->GetType()->IsPrimitiveByte()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 843 | EXPECT_EQ(5, s1->GetByte(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 844 | s1->SetByte(NULL, 6); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 845 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 846 | Field* s2 = statics->FindStaticField("s2", class_linker_->FindClass("C", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 847 | EXPECT_TRUE(s2->GetType()->IsPrimitiveChar()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 848 | EXPECT_EQ('a', s2->GetChar(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 849 | s2->SetChar(NULL, 'b'); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 850 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 851 | Field* s3 = statics->FindStaticField("s3", class_linker_->FindClass("S", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 852 | EXPECT_TRUE(s3->GetType()->IsPrimitiveShort()); |
Ian Rogers | 466bb25 | 2011-10-14 03:29:56 -0700 | [diff] [blame] | 853 | EXPECT_EQ(-536, s3->GetShort(NULL)); |
| 854 | s3->SetShort(NULL, -535); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 855 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 856 | Field* s4 = statics->FindStaticField("s4", class_linker_->FindClass("I", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 857 | EXPECT_TRUE(s4->GetType()->IsPrimitiveInt()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 858 | EXPECT_EQ(2000000000, s4->GetInt(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 859 | s4->SetInt(NULL, 2000000001); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 860 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 861 | Field* s5 = statics->FindStaticField("s5", class_linker_->FindClass("J", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 862 | EXPECT_TRUE(s5->GetType()->IsPrimitiveLong()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 863 | EXPECT_EQ(0x1234567890abcdefLL, s5->GetLong(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 864 | s5->SetLong(NULL, 0x34567890abcdef12LL); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 865 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 866 | Field* s6 = statics->FindStaticField("s6", class_linker_->FindClass("F", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 867 | EXPECT_TRUE(s6->GetType()->IsPrimitiveFloat()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 868 | EXPECT_EQ(0.5, s6->GetFloat(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 869 | s6->SetFloat(NULL, 0.75); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 870 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 871 | Field* s7 = statics->FindStaticField("s7", class_linker_->FindClass("D", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 872 | EXPECT_TRUE(s7->GetType()->IsPrimitiveDouble()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 873 | EXPECT_EQ(16777217, s7->GetDouble(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 874 | s7->SetDouble(NULL, 16777219); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 875 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 876 | Field* s8 = statics->FindStaticField("s8", class_linker_->FindClass("Ljava/lang/String;", class_loader.get())); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 877 | EXPECT_FALSE(s8->GetType()->IsPrimitive()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 878 | EXPECT_TRUE(s8->GetObject(NULL)->AsString()->Equals("android")); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 879 | s8->SetObject(NULL, String::AllocFromModifiedUtf8("robot")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 880 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 881 | EXPECT_EQ(false, s0->GetBoolean(NULL)); |
| 882 | EXPECT_EQ(6, s1->GetByte(NULL)); |
| 883 | EXPECT_EQ('b', s2->GetChar(NULL)); |
Ian Rogers | 466bb25 | 2011-10-14 03:29:56 -0700 | [diff] [blame] | 884 | EXPECT_EQ(-535, s3->GetShort(NULL)); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 885 | EXPECT_EQ(2000000001, s4->GetInt(NULL)); |
| 886 | EXPECT_EQ(0x34567890abcdef12LL, s5->GetLong(NULL)); |
| 887 | EXPECT_EQ(0.75, s6->GetFloat(NULL)); |
| 888 | EXPECT_EQ(16777219, s7->GetDouble(NULL)); |
| 889 | EXPECT_TRUE(s8->GetObject(NULL)->AsString()->Equals("robot")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 890 | } |
| 891 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 892 | TEST_F(ClassLinkerTest, Interfaces) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 893 | SirtRef<ClassLoader> class_loader(LoadDex("Interfaces")); |
| 894 | Class* I = class_linker_->FindClass("LInterfaces$I;", class_loader.get()); |
| 895 | Class* J = class_linker_->FindClass("LInterfaces$J;", class_loader.get()); |
| 896 | Class* K = class_linker_->FindClass("LInterfaces$K;", class_loader.get()); |
| 897 | Class* A = class_linker_->FindClass("LInterfaces$A;", class_loader.get()); |
| 898 | Class* B = class_linker_->FindClass("LInterfaces$B;", class_loader.get()); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 899 | EXPECT_TRUE(I->IsAssignableFrom(A)); |
| 900 | EXPECT_TRUE(J->IsAssignableFrom(A)); |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 901 | EXPECT_TRUE(J->IsAssignableFrom(K)); |
| 902 | EXPECT_TRUE(K->IsAssignableFrom(B)); |
| 903 | EXPECT_TRUE(J->IsAssignableFrom(B)); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 904 | |
| 905 | Method* Ii = I->FindVirtualMethod("i", "()V"); |
| 906 | Method* Jj1 = J->FindVirtualMethod("j1", "()V"); |
| 907 | Method* Jj2 = J->FindVirtualMethod("j2", "()V"); |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 908 | Method* Kj1 = K->FindInterfaceMethod("j1", "()V"); |
| 909 | Method* Kj2 = K->FindInterfaceMethod("j2", "()V"); |
| 910 | Method* Kk = K->FindInterfaceMethod("k", "()V"); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 911 | Method* Ai = A->FindVirtualMethod("i", "()V"); |
| 912 | Method* Aj1 = A->FindVirtualMethod("j1", "()V"); |
| 913 | Method* Aj2 = A->FindVirtualMethod("j2", "()V"); |
| 914 | ASSERT_TRUE(Ii != NULL); |
| 915 | ASSERT_TRUE(Jj1 != NULL); |
| 916 | ASSERT_TRUE(Jj2 != NULL); |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 917 | ASSERT_TRUE(Kj1 != NULL); |
| 918 | ASSERT_TRUE(Kj2 != NULL); |
| 919 | ASSERT_TRUE(Kk != NULL); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 920 | ASSERT_TRUE(Ai != NULL); |
| 921 | ASSERT_TRUE(Aj1 != NULL); |
| 922 | ASSERT_TRUE(Aj2 != NULL); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 923 | EXPECT_NE(Ii, Ai); |
| 924 | EXPECT_NE(Jj1, Aj1); |
| 925 | EXPECT_NE(Jj2, Aj2); |
jeffhao | 5dbddee | 2011-09-07 16:38:26 -0700 | [diff] [blame] | 926 | EXPECT_EQ(Kj1, Jj1); |
| 927 | EXPECT_EQ(Kj2, Jj2); |
Ian Rogers | b04f69f | 2011-10-17 00:40:54 -0700 | [diff] [blame] | 928 | EXPECT_EQ(Ai, A->FindVirtualMethodForInterface(Ii, true)); |
| 929 | EXPECT_EQ(Aj1, A->FindVirtualMethodForInterface(Jj1, true)); |
| 930 | EXPECT_EQ(Aj2, A->FindVirtualMethodForInterface(Jj2, true)); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 931 | EXPECT_EQ(Ai, A->FindVirtualMethodForVirtualOrInterface(Ii)); |
| 932 | EXPECT_EQ(Aj1, A->FindVirtualMethodForVirtualOrInterface(Jj1)); |
| 933 | EXPECT_EQ(Aj2, A->FindVirtualMethodForVirtualOrInterface(Jj2)); |
| 934 | } |
| 935 | |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 936 | TEST_F(ClassLinkerTest, InitializeStaticStorageFromCode) { |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 937 | // 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] | 938 | |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 939 | // case 1, get the uninitialized storage from StaticsFromCode.<clinit> |
| 940 | // case 2, get the initialized storage from StaticsFromCode.getS0 |
Brian Carlstrom | 193a44d | 2011-09-04 12:01:42 -0700 | [diff] [blame] | 941 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 942 | SirtRef<ClassLoader> class_loader(LoadDex("StaticsFromCode")); |
| 943 | const DexFile* dex_file = ClassLoader::GetCompileTimeClassPath(class_loader.get())[0]; |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 944 | CHECK(dex_file != NULL); |
| 945 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame^] | 946 | Class* klass = class_linker_->FindClass("LStaticsFromCode;", class_loader.get()); |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 947 | Method* clinit = klass->FindDirectMethod("<clinit>", "()V"); |
| 948 | Method* getS0 = klass->FindDirectMethod("getS0", "()Ljava/lang/Object;"); |
| 949 | uint32_t type_idx = FindTypeIdxByDescriptor(*dex_file, "LStaticsFromCode;"); |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 950 | |
| 951 | EXPECT_TRUE(clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx) == NULL); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 952 | StaticStorageBase* uninit = InitializeStaticStorage(type_idx, clinit, Thread::Current()); |
Brian Carlstrom | 193a44d | 2011-09-04 12:01:42 -0700 | [diff] [blame] | 953 | EXPECT_TRUE(uninit != NULL); |
| 954 | EXPECT_TRUE(clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx) == NULL); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 955 | StaticStorageBase* init = InitializeStaticStorage(type_idx, getS0, Thread::Current()); |
Brian Carlstrom | 193a44d | 2011-09-04 12:01:42 -0700 | [diff] [blame] | 956 | EXPECT_TRUE(init != NULL); |
| 957 | EXPECT_EQ(init, clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx)); |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Elliott Hughes | 20cde90 | 2011-10-04 17:37:27 -0700 | [diff] [blame] | 960 | TEST_F(ClassLinkerTest, FinalizableBit) { |
| 961 | Class* c; |
| 962 | |
| 963 | // Object has a finalize method, but we know it's empty. |
| 964 | c = class_linker_->FindSystemClass("Ljava/lang/Object;"); |
| 965 | EXPECT_FALSE(c->IsFinalizable()); |
| 966 | |
| 967 | // Enum has a finalize method to prevent its subclasses from implementing one. |
| 968 | c = class_linker_->FindSystemClass("Ljava/lang/Enum;"); |
| 969 | EXPECT_FALSE(c->IsFinalizable()); |
| 970 | |
| 971 | // RoundingMode is an enum. |
| 972 | c = class_linker_->FindSystemClass("Ljava/math/RoundingMode;"); |
| 973 | EXPECT_FALSE(c->IsFinalizable()); |
| 974 | |
| 975 | // RandomAccessFile extends Object and overrides finalize. |
| 976 | c = class_linker_->FindSystemClass("Ljava/io/RandomAccessFile;"); |
| 977 | EXPECT_TRUE(c->IsFinalizable()); |
| 978 | |
| 979 | // FileInputStream is finalizable and extends InputStream which isn't. |
| 980 | c = class_linker_->FindSystemClass("Ljava/io/InputStream;"); |
| 981 | EXPECT_FALSE(c->IsFinalizable()); |
| 982 | c = class_linker_->FindSystemClass("Ljava/io/FileInputStream;"); |
| 983 | EXPECT_TRUE(c->IsFinalizable()); |
| 984 | |
| 985 | // ScheduledThreadPoolExecutor doesn't have a finalize method but |
| 986 | // extends ThreadPoolExecutor which does. |
| 987 | c = class_linker_->FindSystemClass("Ljava/util/concurrent/ThreadPoolExecutor;"); |
| 988 | EXPECT_TRUE(c->IsFinalizable()); |
| 989 | c = class_linker_->FindSystemClass("Ljava/util/concurrent/ScheduledThreadPoolExecutor;"); |
| 990 | EXPECT_TRUE(c->IsFinalizable()); |
| 991 | } |
| 992 | |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 993 | } // namespace art |