summaryrefslogtreecommitdiffstats
path: root/runtime/class_linker_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/class_linker_test.cc')
-rw-r--r--runtime/class_linker_test.cc86
1 files changed, 34 insertions, 52 deletions
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 3f6c5a0..a31a785 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -19,14 +19,13 @@
#include <memory>
#include <string>
+#include "art_field-inl.h"
#include "class_linker-inl.h"
#include "common_runtime_test.h"
#include "dex_file.h"
#include "entrypoints/entrypoint_utils-inl.h"
#include "gc/heap.h"
#include "mirror/accessible_object.h"
-#include "mirror/art_field-inl.h"
-#include "mirror/art_method.h"
#include "mirror/art_method-inl.h"
#include "mirror/class-inl.h"
#include "mirror/dex_cache.h"
@@ -173,10 +172,9 @@ class ClassLinkerTest : public CommonRuntimeTest {
method->GetDeclaringClass()->GetDexCache()->GetResolvedTypes()));
}
- void AssertField(mirror::Class* klass, mirror::ArtField* field)
+ void AssertField(mirror::Class* klass, ArtField* field)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
EXPECT_TRUE(field != nullptr);
- EXPECT_TRUE(field->GetClass() != nullptr);
EXPECT_EQ(klass, field->GetDeclaringClass());
EXPECT_TRUE(field->GetName() != nullptr);
EXPECT_TRUE(field->GetType<true>() != nullptr);
@@ -262,30 +260,27 @@ class ClassLinkerTest : public CommonRuntimeTest {
}
for (size_t i = 0; i < klass->NumInstanceFields(); i++) {
- mirror::ArtField* field = klass->GetInstanceField(i);
+ ArtField* field = klass->GetInstanceField(i);
AssertField(klass.Get(), field);
EXPECT_FALSE(field->IsStatic());
}
for (size_t i = 0; i < klass->NumStaticFields(); i++) {
- mirror::ArtField* field = klass->GetStaticField(i);
+ ArtField* field = klass->GetStaticField(i);
AssertField(klass.Get(), field);
EXPECT_TRUE(field->IsStatic());
}
// Confirm that all instances field offsets are packed together at the start.
EXPECT_GE(klass->NumInstanceFields(), klass->NumReferenceInstanceFields());
- StackHandleScope<1> hs(Thread::Current());
- MutableHandle<mirror::ArtField> fhandle = hs.NewHandle<mirror::ArtField>(nullptr);
MemberOffset start_ref_offset = klass->GetFirstReferenceInstanceFieldOffset();
MemberOffset end_ref_offset(start_ref_offset.Uint32Value() +
klass->NumReferenceInstanceFields() *
sizeof(mirror::HeapReference<mirror::Object>));
MemberOffset current_ref_offset = start_ref_offset;
for (size_t i = 0; i < klass->NumInstanceFields(); i++) {
- mirror::ArtField* field = klass->GetInstanceField(i);
- fhandle.Assign(field);
- mirror::Class* field_type = fhandle->GetType<true>();
+ ArtField* field = klass->GetInstanceField(i);
+ mirror::Class* field_type = field->GetType<true>();
ASSERT_TRUE(field_type != nullptr);
if (!field->IsPrimitiveType()) {
ASSERT_TRUE(!field_type->IsPrimitive());
@@ -293,7 +288,7 @@ class ClassLinkerTest : public CommonRuntimeTest {
if (current_ref_offset.Uint32Value() == end_ref_offset.Uint32Value()) {
// While Reference.referent is not primitive, the ClassLinker
// treats it as such so that the garbage collector won't scan it.
- EXPECT_EQ(PrettyField(fhandle.Get()),
+ EXPECT_EQ(PrettyField(field),
"java.lang.Object java.lang.ref.Reference.referent");
} else {
current_ref_offset = MemberOffset(current_ref_offset.Uint32Value() +
@@ -425,7 +420,7 @@ struct CheckOffsets {
}
for (size_t i = 0; i < offsets.size(); i++) {
- mirror::ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
+ ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
StringPiece field_name(field->GetName());
if (field_name != offsets[i].java_name) {
error = true;
@@ -434,7 +429,7 @@ struct CheckOffsets {
if (error) {
for (size_t i = 0; i < offsets.size(); i++) {
CheckOffset& offset = offsets[i];
- mirror::ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
+ ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
StringPiece field_name(field->GetName());
if (field_name != offsets[i].java_name) {
LOG(ERROR) << "JAVA FIELD ORDER MISMATCH NEXT LINE:";
@@ -448,7 +443,7 @@ struct CheckOffsets {
for (size_t i = 0; i < offsets.size(); i++) {
CheckOffset& offset = offsets[i];
- mirror::ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
+ ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
if (field->GetOffset().Uint32Value() != offset.cpp_offset) {
error = true;
}
@@ -456,7 +451,7 @@ struct CheckOffsets {
if (error) {
for (size_t i = 0; i < offsets.size(); i++) {
CheckOffset& offset = offsets[i];
- mirror::ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
+ ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
if (field->GetOffset().Uint32Value() != offset.cpp_offset) {
LOG(ERROR) << "OFFSET MISMATCH NEXT LINE:";
}
@@ -486,15 +481,6 @@ struct ObjectOffsets : public CheckOffsets<mirror::Object> {
};
};
-struct ArtFieldOffsets : public CheckOffsets<mirror::ArtField> {
- ArtFieldOffsets() : CheckOffsets<mirror::ArtField>(false, "Ljava/lang/reflect/ArtField;") {
- offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::ArtField, access_flags_), "accessFlags"));
- offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::ArtField, declaring_class_), "declaringClass"));
- offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::ArtField, field_dex_idx_), "fieldDexIndex"));
- offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::ArtField, offset_), "offset"));
- };
-};
-
struct ArtMethodOffsets : public CheckOffsets<mirror::ArtMethod> {
ArtMethodOffsets() : CheckOffsets<mirror::ArtMethod>(false, "Ljava/lang/reflect/ArtMethod;") {
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::ArtMethod, access_flags_), "accessFlags"));
@@ -522,8 +508,10 @@ struct ClassOffsets : public CheckOffsets<mirror::Class> {
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, ifields_), "iFields"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, iftable_), "ifTable"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, name_), "name"));
+ offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, num_instance_fields_), "numInstanceFields"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, num_reference_instance_fields_), "numReferenceInstanceFields"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, num_reference_static_fields_), "numReferenceStaticFields"));
+ offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, num_static_fields_), "numStaticFields"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, object_size_), "objectSize"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, primitive_type_), "primitiveType"));
offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, reference_instance_offsets_), "referenceInstanceOffsets"));
@@ -629,7 +617,6 @@ struct FieldOffsets : public CheckOffsets<mirror::Field> {
TEST_F(ClassLinkerTest, ValidateFieldOrderOfJavaCppUnionClasses) {
ScopedObjectAccess soa(Thread::Current());
EXPECT_TRUE(ObjectOffsets().Check());
- EXPECT_TRUE(ArtFieldOffsets().Check());
EXPECT_TRUE(ArtMethodOffsets().Check());
EXPECT_TRUE(ClassOffsets().Check());
EXPECT_TRUE(StringOffsets().Check());
@@ -844,21 +831,21 @@ TEST_F(ClassLinkerTest, ValidateBoxedTypes) {
NullHandle<mirror::ClassLoader> class_loader;
mirror::Class* c;
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Boolean;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Byte;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Character;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Double;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Float;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Integer;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Long;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/Short;", class_loader);
- EXPECT_STREQ("value", c->GetIFields()->Get(0)->GetName());
+ EXPECT_STREQ("value", c->GetIFields()[0].GetName());
}
TEST_F(ClassLinkerTest, TwoClassLoadersOneClass) {
@@ -892,49 +879,47 @@ TEST_F(ClassLinkerTest, StaticFields) {
EXPECT_EQ(9U, statics->NumStaticFields());
- mirror::ArtField* s0 = mirror::Class::FindStaticField(soa.Self(), statics, "s0", "Z");
- std::string temp;
- EXPECT_STREQ(s0->GetClass()->GetDescriptor(&temp), "Ljava/lang/reflect/ArtField;");
+ ArtField* s0 = mirror::Class::FindStaticField(soa.Self(), statics, "s0", "Z");
EXPECT_EQ(s0->GetTypeAsPrimitiveType(), Primitive::kPrimBoolean);
EXPECT_EQ(true, s0->GetBoolean(statics.Get()));
s0->SetBoolean<false>(statics.Get(), false);
- mirror::ArtField* s1 = mirror::Class::FindStaticField(soa.Self(), statics, "s1", "B");
+ ArtField* s1 = mirror::Class::FindStaticField(soa.Self(), statics, "s1", "B");
EXPECT_EQ(s1->GetTypeAsPrimitiveType(), Primitive::kPrimByte);
EXPECT_EQ(5, s1->GetByte(statics.Get()));
s1->SetByte<false>(statics.Get(), 6);
- mirror::ArtField* s2 = mirror::Class::FindStaticField(soa.Self(), statics, "s2", "C");
+ ArtField* s2 = mirror::Class::FindStaticField(soa.Self(), statics, "s2", "C");
EXPECT_EQ(s2->GetTypeAsPrimitiveType(), Primitive::kPrimChar);
EXPECT_EQ('a', s2->GetChar(statics.Get()));
s2->SetChar<false>(statics.Get(), 'b');
- mirror::ArtField* s3 = mirror::Class::FindStaticField(soa.Self(), statics, "s3", "S");
+ ArtField* s3 = mirror::Class::FindStaticField(soa.Self(), statics, "s3", "S");
EXPECT_EQ(s3->GetTypeAsPrimitiveType(), Primitive::kPrimShort);
EXPECT_EQ(-536, s3->GetShort(statics.Get()));
s3->SetShort<false>(statics.Get(), -535);
- mirror::ArtField* s4 = mirror::Class::FindStaticField(soa.Self(), statics, "s4", "I");
+ ArtField* s4 = mirror::Class::FindStaticField(soa.Self(), statics, "s4", "I");
EXPECT_EQ(s4->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
EXPECT_EQ(2000000000, s4->GetInt(statics.Get()));
s4->SetInt<false>(statics.Get(), 2000000001);
- mirror::ArtField* s5 = mirror::Class::FindStaticField(soa.Self(), statics, "s5", "J");
+ ArtField* s5 = mirror::Class::FindStaticField(soa.Self(), statics, "s5", "J");
EXPECT_EQ(s5->GetTypeAsPrimitiveType(), Primitive::kPrimLong);
EXPECT_EQ(0x1234567890abcdefLL, s5->GetLong(statics.Get()));
s5->SetLong<false>(statics.Get(), INT64_C(0x34567890abcdef12));
- mirror::ArtField* s6 = mirror::Class::FindStaticField(soa.Self(), statics, "s6", "F");
+ ArtField* s6 = mirror::Class::FindStaticField(soa.Self(), statics, "s6", "F");
EXPECT_EQ(s6->GetTypeAsPrimitiveType(), Primitive::kPrimFloat);
EXPECT_DOUBLE_EQ(0.5, s6->GetFloat(statics.Get()));
s6->SetFloat<false>(statics.Get(), 0.75);
- mirror::ArtField* s7 = mirror::Class::FindStaticField(soa.Self(), statics, "s7", "D");
+ ArtField* s7 = mirror::Class::FindStaticField(soa.Self(), statics, "s7", "D");
EXPECT_EQ(s7->GetTypeAsPrimitiveType(), Primitive::kPrimDouble);
EXPECT_DOUBLE_EQ(16777217.0, s7->GetDouble(statics.Get()));
s7->SetDouble<false>(statics.Get(), 16777219);
- mirror::ArtField* s8 = mirror::Class::FindStaticField(soa.Self(), statics, "s8",
+ ArtField* s8 = mirror::Class::FindStaticField(soa.Self(), statics, "s8",
"Ljava/lang/String;");
EXPECT_EQ(s8->GetTypeAsPrimitiveType(), Primitive::kPrimNot);
EXPECT_TRUE(s8->GetObject(statics.Get())->AsString()->Equals("android"));
@@ -1006,13 +991,13 @@ TEST_F(ClassLinkerTest, Interfaces) {
EXPECT_EQ(Aj1, A->FindVirtualMethodForVirtualOrInterface(Jj1));
EXPECT_EQ(Aj2, A->FindVirtualMethodForVirtualOrInterface(Jj2));
- mirror::ArtField* Afoo = mirror::Class::FindStaticField(soa.Self(), A, "foo",
+ ArtField* Afoo = mirror::Class::FindStaticField(soa.Self(), A, "foo",
"Ljava/lang/String;");
- mirror::ArtField* Bfoo = mirror::Class::FindStaticField(soa.Self(), B, "foo",
+ ArtField* Bfoo = mirror::Class::FindStaticField(soa.Self(), B, "foo",
"Ljava/lang/String;");
- mirror::ArtField* Jfoo = mirror::Class::FindStaticField(soa.Self(), J, "foo",
+ ArtField* Jfoo = mirror::Class::FindStaticField(soa.Self(), J, "foo",
"Ljava/lang/String;");
- mirror::ArtField* Kfoo = mirror::Class::FindStaticField(soa.Self(), K, "foo",
+ ArtField* Kfoo = mirror::Class::FindStaticField(soa.Self(), K, "foo",
"Ljava/lang/String;");
ASSERT_TRUE(Afoo != nullptr);
EXPECT_EQ(Afoo, Bfoo);
@@ -1110,9 +1095,6 @@ TEST_F(ClassLinkerTest, ValidatePredefinedClassSizes) {
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/DexCache;", class_loader);
EXPECT_EQ(c->GetClassSize(), mirror::DexCache::ClassSize());
- c = class_linker_->FindClass(soa.Self(), "Ljava/lang/reflect/ArtField;", class_loader);
- EXPECT_EQ(c->GetClassSize(), mirror::ArtField::ClassSize());
-
c = class_linker_->FindClass(soa.Self(), "Ljava/lang/reflect/ArtMethod;", class_loader);
EXPECT_EQ(c->GetClassSize(), mirror::ArtMethod::ClassSize());
}