Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedByteFieldAccessorImpl.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 UnsafeQualifiedByteFieldAccessorImpl30extends UnsafeQualifiedFieldAccessorImpl31{32UnsafeQualifiedByteFieldAccessorImpl(Field field, boolean isReadOnly) {33super(field, isReadOnly);34}3536public Object get(Object obj) throws IllegalArgumentException {37return Byte.valueOf(getByte(obj));38}3940public boolean getBoolean(Object obj) throws IllegalArgumentException {41throw newGetBooleanIllegalArgumentException();42}4344public byte getByte(Object obj) throws IllegalArgumentException {45ensureObj(obj);46return unsafe.getByteVolatile(obj, fieldOffset);47}4849public char getChar(Object obj) throws IllegalArgumentException {50throw newGetCharIllegalArgumentException();51}5253public short getShort(Object obj) throws IllegalArgumentException {54return getByte(obj);55}5657public int getInt(Object obj) throws IllegalArgumentException {58return getByte(obj);59}6061public long getLong(Object obj) throws IllegalArgumentException {62return getByte(obj);63}6465public float getFloat(Object obj) throws IllegalArgumentException {66return getByte(obj);67}6869public double getDouble(Object obj) throws IllegalArgumentException {70return getByte(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.putByteVolatile(obj, fieldOffset, ((Byte) value).byteValue());85return;86}87throwSetIllegalArgumentException(value);88}8990public void setBoolean(Object obj, boolean z)91throws IllegalArgumentException, IllegalAccessException92{93throwSetIllegalArgumentException(z);94}9596public void setByte(Object obj, byte b)97throws IllegalArgumentException, IllegalAccessException98{99ensureObj(obj);100if (isReadOnly) {101throwFinalFieldIllegalAccessException(b);102}103unsafe.putByteVolatile(obj, fieldOffset, b);104}105106public void setChar(Object obj, char c)107throws IllegalArgumentException, IllegalAccessException108{109throwSetIllegalArgumentException(c);110}111112public void setShort(Object obj, short s)113throws IllegalArgumentException, IllegalAccessException114{115throwSetIllegalArgumentException(s);116}117118public void setInt(Object obj, int i)119throws IllegalArgumentException, IllegalAccessException120{121throwSetIllegalArgumentException(i);122}123124public void setLong(Object obj, long l)125throws IllegalArgumentException, IllegalAccessException126{127throwSetIllegalArgumentException(l);128}129130public void setFloat(Object obj, float f)131throws IllegalArgumentException, IllegalAccessException132{133throwSetIllegalArgumentException(f);134}135136public void setDouble(Object obj, double d)137throws IllegalArgumentException, IllegalAccessException138{139throwSetIllegalArgumentException(d);140}141}142143144