Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedFloatFieldAccessorImpl.java
41159 views
/*1* Copyright (c) 2004, 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 UnsafeQualifiedFloatFieldAccessorImpl30extends UnsafeQualifiedFieldAccessorImpl31{32UnsafeQualifiedFloatFieldAccessorImpl(Field field, boolean isReadOnly) {33super(field, isReadOnly);34}3536public Object get(Object obj) throws IllegalArgumentException {37return Float.valueOf(getFloat(obj));38}3940public boolean getBoolean(Object obj) throws IllegalArgumentException {41throw newGetBooleanIllegalArgumentException();42}4344public byte getByte(Object obj) throws IllegalArgumentException {45throw newGetByteIllegalArgumentException();46}4748public char getChar(Object obj) throws IllegalArgumentException {49throw newGetCharIllegalArgumentException();50}5152public short getShort(Object obj) throws IllegalArgumentException {53throw newGetShortIllegalArgumentException();54}5556public int getInt(Object obj) throws IllegalArgumentException {57throw newGetIntIllegalArgumentException();58}5960public long getLong(Object obj) throws IllegalArgumentException {61throw newGetLongIllegalArgumentException();62}6364public float getFloat(Object obj) throws IllegalArgumentException {65ensureObj(obj);66return unsafe.getFloatVolatile(obj, fieldOffset);67}6869public double getDouble(Object obj) throws IllegalArgumentException {70return getFloat(obj);71}7273public void set(Object obj, Object value)74throws IllegalArgumentException, IllegalAccessException75{76ensureObj(obj);77if (isReadOnly) {78throwFinalFieldIllegalAccessException(value);79}80if (value == null) {81throwSetIllegalArgumentException(value);82}83if (value instanceof Byte) {84unsafe.putFloatVolatile(obj, fieldOffset, ((Byte) value).byteValue());85return;86}87if (value instanceof Short) {88unsafe.putFloatVolatile(obj, fieldOffset, ((Short) value).shortValue());89return;90}91if (value instanceof Character) {92unsafe.putFloatVolatile(obj, fieldOffset, ((Character) value).charValue());93return;94}95if (value instanceof Integer) {96unsafe.putFloatVolatile(obj, fieldOffset, ((Integer) value).intValue());97return;98}99if (value instanceof Long) {100unsafe.putFloatVolatile(obj, fieldOffset, ((Long) value).longValue());101return;102}103if (value instanceof Float) {104unsafe.putFloatVolatile(obj, fieldOffset, ((Float) value).floatValue());105return;106}107throwSetIllegalArgumentException(value);108}109110public void setBoolean(Object obj, boolean z)111throws IllegalArgumentException, IllegalAccessException112{113throwSetIllegalArgumentException(z);114}115116public void setByte(Object obj, byte b)117throws IllegalArgumentException, IllegalAccessException118{119setFloat(obj, b);120}121122public void setChar(Object obj, char c)123throws IllegalArgumentException, IllegalAccessException124{125setFloat(obj, c);126}127128public void setShort(Object obj, short s)129throws IllegalArgumentException, IllegalAccessException130{131setFloat(obj, s);132}133134public void setInt(Object obj, int i)135throws IllegalArgumentException, IllegalAccessException136{137setFloat(obj, i);138}139140public void setLong(Object obj, long l)141throws IllegalArgumentException, IllegalAccessException142{143setFloat(obj, l);144}145146public void setFloat(Object obj, float f)147throws IllegalArgumentException, IllegalAccessException148{149ensureObj(obj);150if (isReadOnly) {151throwFinalFieldIllegalAccessException(f);152}153unsafe.putFloatVolatile(obj, fieldOffset, f);154}155156public void setDouble(Object obj, double d)157throws IllegalArgumentException, IllegalAccessException158{159throwSetIllegalArgumentException(d);160}161}162163164