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