blob: f91cab1036e88e7e657fe875f5941f4310b45a9f [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"
Ian Rogers62f05122014-03-21 11:21:29 -070024#include "scoped_thread_state_change.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "utils.h"
Ian Rogers62f05122014-03-21 11:21:29 -070026#include "well_known_classes.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027
28namespace art {
29namespace mirror {
30
31// TODO: get global references for these
Brian Carlstromea46f952013-07-30 01:26:50 -070032Class* ArtField::java_lang_reflect_ArtField_ = NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033
Ian Rogers62f05122014-03-21 11:21:29 -070034ArtField* ArtField::FromReflectedField(const ScopedObjectAccess& soa, jobject jlr_field) {
35 mirror::ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_reflect_Field_artField);
36 mirror::ArtField* field = f->GetObject(soa.Decode<mirror::Object*>(jlr_field))->AsArtField();
37 DCHECK(field != nullptr);
38 return field;
39}
40
Brian Carlstromea46f952013-07-30 01:26:50 -070041void ArtField::SetClass(Class* java_lang_reflect_ArtField) {
42 CHECK(java_lang_reflect_ArtField_ == NULL);
43 CHECK(java_lang_reflect_ArtField != NULL);
44 java_lang_reflect_ArtField_ = java_lang_reflect_ArtField;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045}
46
Brian Carlstromea46f952013-07-30 01:26:50 -070047void ArtField::ResetClass() {
48 CHECK(java_lang_reflect_ArtField_ != NULL);
49 java_lang_reflect_ArtField_ = NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050}
51
Brian Carlstromea46f952013-07-30 01:26:50 -070052void ArtField::SetOffset(MemberOffset num_bytes) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010054 if (kIsDebugBuild && Runtime::Current()->IsCompiler() &&
55 !Runtime::Current()->UseCompileTimeClassPath()) {
56 Primitive::Type type = FieldHelper(this).GetTypeAsPrimitiveType();
57 if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) {
58 DCHECK_ALIGNED(num_bytes.Uint32Value(), 8);
59 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010061 // Not called within a transaction.
62 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtField, offset_), num_bytes.Uint32Value(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063}
64
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080065void ArtField::VisitRoots(RootCallback* callback, void* arg) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -080066 if (java_lang_reflect_ArtField_ != nullptr) {
Mathieu Chartier815873e2014-02-13 18:02:13 -080067 callback(reinterpret_cast<mirror::Object**>(&java_lang_reflect_ArtField_), arg, 0,
68 kRootStickyClass);
Mathieu Chartierc528dba2013-11-26 12:00:11 -080069 }
70}
71
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072} // namespace mirror
73} // namespace art