1 /*
2  * Copyright (C) 2017 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 
17 package java.lang.invoke;
18 
19 import java.lang.reflect.Field;
20 import java.lang.reflect.Modifier;
21 
22 /**
23  * A VarHandle that's associated with an ArtField.
24  * @hide
25  */
26 final class FieldVarHandle extends VarHandle {
27     private final long artField;
28 
FieldVarHandle(Field field, Class<?> declaringClass)29     private FieldVarHandle(Field field, Class<?> declaringClass) {
30         super(field.getType(), Modifier.isFinal(field.getModifiers()), declaringClass);
31         artField = field.getArtField();
32     }
33 
FieldVarHandle(Field field)34     private FieldVarHandle(Field field) {
35         super(field.getType(), Modifier.isFinal(field.getModifiers()));
36         artField = field.getArtField();
37     }
38 
create(Field field)39     static FieldVarHandle create(Field field) {
40         if (Modifier.isStatic(field.getModifiers())) {
41             return new FieldVarHandle(field);
42         } else {
43             return new FieldVarHandle(field, field.getDeclaringClass());
44         }
45     }
46 }
47