Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedLongFieldAccessorImpl.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 UnsafeQualifiedLongFieldAccessorImpl30extends UnsafeQualifiedFieldAccessorImpl31{32UnsafeQualifiedLongFieldAccessorImpl(Field field, boolean isReadOnly) {33super(field, isReadOnly);34}3536public Object get(Object obj) throws IllegalArgumentException {37return Long.valueOf(getLong(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 {61ensureObj(obj);62return unsafe.getLongVolatile(obj, fieldOffset);63}6465public float getFloat(Object obj) throws IllegalArgumentException {66return getLong(obj);67}6869public double getDouble(Object obj) throws IllegalArgumentException {70return getLong(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.putLongVolatile(obj, fieldOffset, ((Byte) value).byteValue());85return;86}87if (value instanceof Short) {88unsafe.putLongVolatile(obj, fieldOffset, ((Short) value).shortValue());89return;90}91if (value instanceof Character) {92unsafe.putLongVolatile(obj, fieldOffset, ((Character) value).charValue());93return;94}95if (value instanceof Integer) {96unsafe.putLongVolatile(obj, fieldOffset, ((Integer) value).intValue());97return;98}99if (value instanceof Long) {100unsafe.putLongVolatile(obj, fieldOffset, ((Long) value).longValue());101return;102}103throwSetIllegalArgumentException(value);104}105106public void setBoolean(Object obj, boolean z)107throws IllegalArgumentException, IllegalAccessException108{109throwSetIllegalArgumentException(z);110}111112public void setByte(Object obj, byte b)113throws IllegalArgumentException, IllegalAccessException114{115setLong(obj, b);116}117118public void setChar(Object obj, char c)119throws IllegalArgumentException, IllegalAccessException120{121setLong(obj, c);122}123124public void setShort(Object obj, short s)125throws IllegalArgumentException, IllegalAccessException126{127setLong(obj, s);128}129130public void setInt(Object obj, int i)131throws IllegalArgumentException, IllegalAccessException132{133setLong(obj, i);134}135136public void setLong(Object obj, long l)137throws IllegalArgumentException, IllegalAccessException138{139ensureObj(obj);140if (isReadOnly) {141throwFinalFieldIllegalAccessException(l);142}143unsafe.putLongVolatile(obj, fieldOffset, l);144}145146public void setFloat(Object obj, float f)147throws IllegalArgumentException, IllegalAccessException148{149throwSetIllegalArgumentException(f);150}151152public void setDouble(Object obj, double d)153throws IllegalArgumentException, IllegalAccessException154{155throwSetIllegalArgumentException(d);156}157}158159160