Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeDoubleFieldAccessorImpl.java
41159 views
/*1* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.reflect;2627import java.lang.reflect.Field;2829class UnsafeDoubleFieldAccessorImpl extends UnsafeFieldAccessorImpl {30UnsafeDoubleFieldAccessorImpl(Field field) {31super(field);32}3334public Object get(Object obj) throws IllegalArgumentException {35return Double.valueOf(getDouble(obj));36}3738public boolean getBoolean(Object obj) throws IllegalArgumentException {39throw newGetBooleanIllegalArgumentException();40}4142public byte getByte(Object obj) throws IllegalArgumentException {43throw newGetByteIllegalArgumentException();44}4546public char getChar(Object obj) throws IllegalArgumentException {47throw newGetCharIllegalArgumentException();48}4950public short getShort(Object obj) throws IllegalArgumentException {51throw newGetShortIllegalArgumentException();52}5354public int getInt(Object obj) throws IllegalArgumentException {55throw newGetIntIllegalArgumentException();56}5758public long getLong(Object obj) throws IllegalArgumentException {59throw newGetLongIllegalArgumentException();60}6162public float getFloat(Object obj) throws IllegalArgumentException {63throw newGetFloatIllegalArgumentException();64}6566public double getDouble(Object obj) throws IllegalArgumentException {67ensureObj(obj);68return unsafe.getDouble(obj, fieldOffset);69}7071public void set(Object obj, Object value)72throws IllegalArgumentException, IllegalAccessException73{74ensureObj(obj);75if (isFinal) {76throwFinalFieldIllegalAccessException(value);77}78if (value == null) {79throwSetIllegalArgumentException(value);80}81if (value instanceof Byte) {82unsafe.putDouble(obj, fieldOffset, ((Byte) value).byteValue());83return;84}85if (value instanceof Short) {86unsafe.putDouble(obj, fieldOffset, ((Short) value).shortValue());87return;88}89if (value instanceof Character) {90unsafe.putDouble(obj, fieldOffset, ((Character) value).charValue());91return;92}93if (value instanceof Integer) {94unsafe.putDouble(obj, fieldOffset, ((Integer) value).intValue());95return;96}97if (value instanceof Long) {98unsafe.putDouble(obj, fieldOffset, ((Long) value).longValue());99return;100}101if (value instanceof Float) {102unsafe.putDouble(obj, fieldOffset, ((Float) value).floatValue());103return;104}105if (value instanceof Double) {106unsafe.putDouble(obj, fieldOffset, ((Double) value).doubleValue());107return;108}109throwSetIllegalArgumentException(value);110}111112public void setBoolean(Object obj, boolean z)113throws IllegalArgumentException, IllegalAccessException114{115throwSetIllegalArgumentException(z);116}117118public void setByte(Object obj, byte b)119throws IllegalArgumentException, IllegalAccessException120{121setDouble(obj, b);122}123124public void setChar(Object obj, char c)125throws IllegalArgumentException, IllegalAccessException126{127setDouble(obj, c);128}129130public void setShort(Object obj, short s)131throws IllegalArgumentException, IllegalAccessException132{133setDouble(obj, s);134}135136public void setInt(Object obj, int i)137throws IllegalArgumentException, IllegalAccessException138{139setDouble(obj, i);140}141142public void setLong(Object obj, long l)143throws IllegalArgumentException, IllegalAccessException144{145setDouble(obj, l);146}147148public void setFloat(Object obj, float f)149throws IllegalArgumentException, IllegalAccessException150{151setDouble(obj, f);152}153154public void setDouble(Object obj, double d)155throws IllegalArgumentException, IllegalAccessException156{157ensureObj(obj);158if (isFinal) {159throwFinalFieldIllegalAccessException(d);160}161unsafe.putDouble(obj, fieldOffset, d);162}163}164165166