blob: c3a4efb15ae04761e9d91a1ba5dc190dea27bbe7 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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 */
16
Brian Carlstromea46f952013-07-30 01:26:50 -070017#include "art_field.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080018
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "art_field-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070020#include "gc/accounting/card_table-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "object-inl.h"
22#include "object_utils.h"
23#include "runtime.h"
24#include "utils.h"
25
26namespace art {
27namespace mirror {
28
29// TODO: get global references for these
Brian Carlstromea46f952013-07-30 01:26:50 -070030Class* ArtField::java_lang_reflect_ArtField_ = NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
Brian Carlstromea46f952013-07-30 01:26:50 -070032void ArtField::SetClass(Class* java_lang_reflect_ArtField) {
33 CHECK(java_lang_reflect_ArtField_ == NULL);
34 CHECK(java_lang_reflect_ArtField != NULL);
35 java_lang_reflect_ArtField_ = java_lang_reflect_ArtField;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036}
37
Brian Carlstromea46f952013-07-30 01:26:50 -070038void ArtField::ResetClass() {
39 CHECK(java_lang_reflect_ArtField_ != NULL);
40 java_lang_reflect_ArtField_ = NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041}
42
Brian Carlstromea46f952013-07-30 01:26:50 -070043void ArtField::SetOffset(MemberOffset num_bytes) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstrom7934ac22013-07-26 10:54:15 -070045#if 0 // TODO enable later in boot and under !NDEBUG
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 FieldHelper fh(this);
47 Primitive::Type type = fh.GetTypeAsPrimitiveType();
48 if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) {
49 DCHECK_ALIGNED(num_bytes.Uint32Value(), 8);
50 }
51#endif
Brian Carlstromea46f952013-07-30 01:26:50 -070052 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, offset_), num_bytes.Uint32Value(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053}
54
Mathieu Chartierc528dba2013-11-26 12:00:11 -080055void ArtField::VisitRoots(RootVisitor* visitor, void* arg) {
56 if (java_lang_reflect_ArtField_ != nullptr) {
57 java_lang_reflect_ArtField_ = down_cast<mirror::Class*>(
58 visitor(java_lang_reflect_ArtField_, arg));
59 }
60}
61
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062} // namespace mirror
63} // namespace art