Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeFloatFieldAccessorImpl.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 UnsafeFloatFieldAccessorImpl extends UnsafeFieldAccessorImpl {30UnsafeFloatFieldAccessorImpl(Field field) {31super(field);32}3334public Object get(Object obj) throws IllegalArgumentException {35return Float.valueOf(getFloat(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 {63ensureObj(obj);64return unsafe.getFloat(obj, fieldOffset);65}6667public double getDouble(Object obj) throws IllegalArgumentException {68return getFloat(obj);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.putFloat(obj, fieldOffset, ((Byte) value).byteValue());83return;84}85if (value instanceof Short) {86unsafe.putFloat(obj, fieldOffset, ((Short) value).shortValue());87return;88}89if (value instanceof Character) {90unsafe.putFloat(obj, fieldOffset, ((Character) value).charValue());91return;92}93if (value instanceof Integer) {94unsafe.putFloat(obj, fieldOffset, ((Integer) value).intValue());95return;96}97if (value instanceof Long) {98unsafe.putFloat(obj, fieldOffset, ((Long) value).longValue());99return;100}101if (value instanceof Float) {102unsafe.putFloat(obj, fieldOffset, ((Float) value).floatValue());103return;104}105throwSetIllegalArgumentException(value);106}107108public void setBoolean(Object obj, boolean z)109throws IllegalArgumentException, IllegalAccessException110{111throwSetIllegalArgumentException(z);112}113114public void setByte(Object obj, byte b)115throws IllegalArgumentException, IllegalAccessException116{117setFloat(obj, b);118}119120public void setChar(Object obj, char c)121throws IllegalArgumentException, IllegalAccessException122{123setFloat(obj, c);124}125126public void setShort(Object obj, short s)127throws IllegalArgumentException, IllegalAccessException128{129setFloat(obj, s);130}131132public void setInt(Object obj, int i)133throws IllegalArgumentException, IllegalAccessException134{135setFloat(obj, i);136}137138public void setLong(Object obj, long l)139throws IllegalArgumentException, IllegalAccessException140{141setFloat(obj, l);142}143144public void setFloat(Object obj, float f)145throws IllegalArgumentException, IllegalAccessException146{147ensureObj(obj);148if (isFinal) {149throwFinalFieldIllegalAccessException(f);150}151unsafe.putFloat(obj, fieldOffset, f);152}153154public void setDouble(Object obj, double d)155throws IllegalArgumentException, IllegalAccessException156{157throwSetIllegalArgumentException(d);158}159}160161162