1 /*
2  * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package jdk.internal.reflect;
27 
28 import java.lang.reflect.Field;
29 
30 class UnsafeDoubleFieldAccessorImpl extends UnsafeFieldAccessorImpl {
UnsafeDoubleFieldAccessorImpl(Field field)31     UnsafeDoubleFieldAccessorImpl(Field field) {
32         super(field);
33     }
34 
get(Object obj)35     public Object get(Object obj) throws IllegalArgumentException {
36         return Double.valueOf(getDouble(obj));
37     }
38 
getBoolean(Object obj)39     public boolean getBoolean(Object obj) throws IllegalArgumentException {
40         throw newGetBooleanIllegalArgumentException();
41     }
42 
getByte(Object obj)43     public byte getByte(Object obj) throws IllegalArgumentException {
44         throw newGetByteIllegalArgumentException();
45     }
46 
getChar(Object obj)47     public char getChar(Object obj) throws IllegalArgumentException {
48         throw newGetCharIllegalArgumentException();
49     }
50 
getShort(Object obj)51     public short getShort(Object obj) throws IllegalArgumentException {
52         throw newGetShortIllegalArgumentException();
53     }
54 
getInt(Object obj)55     public int getInt(Object obj) throws IllegalArgumentException {
56         throw newGetIntIllegalArgumentException();
57     }
58 
getLong(Object obj)59     public long getLong(Object obj) throws IllegalArgumentException {
60         throw newGetLongIllegalArgumentException();
61     }
62 
getFloat(Object obj)63     public float getFloat(Object obj) throws IllegalArgumentException {
64         throw newGetFloatIllegalArgumentException();
65     }
66 
getDouble(Object obj)67     public double getDouble(Object obj) throws IllegalArgumentException {
68         ensureObj(obj);
69         return unsafe.getDouble(obj, fieldOffset);
70     }
71 
set(Object obj, Object value)72     public void set(Object obj, Object value)
73         throws IllegalArgumentException, IllegalAccessException
74     {
75         ensureObj(obj);
76         if (isFinal) {
77             throwFinalFieldIllegalAccessException(value);
78         }
79         if (value == null) {
80             throwSetIllegalArgumentException(value);
81         }
82         if (value instanceof Byte) {
83             unsafe.putDouble(obj, fieldOffset, ((Byte) value).byteValue());
84             return;
85         }
86         if (value instanceof Short) {
87             unsafe.putDouble(obj, fieldOffset, ((Short) value).shortValue());
88             return;
89         }
90         if (value instanceof Character) {
91             unsafe.putDouble(obj, fieldOffset, ((Character) value).charValue());
92             return;
93         }
94         if (value instanceof Integer) {
95             unsafe.putDouble(obj, fieldOffset, ((Integer) value).intValue());
96             return;
97         }
98         if (value instanceof Long) {
99             unsafe.putDouble(obj, fieldOffset, ((Long) value).longValue());
100             return;
101         }
102         if (value instanceof Float) {
103             unsafe.putDouble(obj, fieldOffset, ((Float) value).floatValue());
104             return;
105         }
106         if (value instanceof Double) {
107             unsafe.putDouble(obj, fieldOffset, ((Double) value).doubleValue());
108             return;
109         }
110         throwSetIllegalArgumentException(value);
111     }
112 
setBoolean(Object obj, boolean z)113     public void setBoolean(Object obj, boolean z)
114         throws IllegalArgumentException, IllegalAccessException
115     {
116         throwSetIllegalArgumentException(z);
117     }
118 
setByte(Object obj, byte b)119     public void setByte(Object obj, byte b)
120         throws IllegalArgumentException, IllegalAccessException
121     {
122         setDouble(obj, b);
123     }
124 
setChar(Object obj, char c)125     public void setChar(Object obj, char c)
126         throws IllegalArgumentException, IllegalAccessException
127     {
128         setDouble(obj, c);
129     }
130 
setShort(Object obj, short s)131     public void setShort(Object obj, short s)
132         throws IllegalArgumentException, IllegalAccessException
133     {
134         setDouble(obj, s);
135     }
136 
setInt(Object obj, int i)137     public void setInt(Object obj, int i)
138         throws IllegalArgumentException, IllegalAccessException
139     {
140         setDouble(obj, i);
141     }
142 
setLong(Object obj, long l)143     public void setLong(Object obj, long l)
144         throws IllegalArgumentException, IllegalAccessException
145     {
146         setDouble(obj, l);
147     }
148 
setFloat(Object obj, float f)149     public void setFloat(Object obj, float f)
150         throws IllegalArgumentException, IllegalAccessException
151     {
152         setDouble(obj, f);
153     }
154 
setDouble(Object obj, double d)155     public void setDouble(Object obj, double d)
156         throws IllegalArgumentException, IllegalAccessException
157     {
158         ensureObj(obj);
159         if (isFinal) {
160             throwFinalFieldIllegalAccessException(d);
161         }
162         unsafe.putDouble(obj, fieldOffset, d);
163     }
164 }
165