Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedObjectFieldAccessorImpl.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 UnsafeQualifiedObjectFieldAccessorImpl30extends UnsafeQualifiedFieldAccessorImpl31{32UnsafeQualifiedObjectFieldAccessorImpl(Field field, boolean isReadOnly) {33super(field, isReadOnly);34}3536public Object get(Object obj) throws IllegalArgumentException {37ensureObj(obj);38return unsafe.getReferenceVolatile(obj, fieldOffset);39}4041public boolean getBoolean(Object obj) throws IllegalArgumentException {42throw newGetBooleanIllegalArgumentException();43}4445public byte getByte(Object obj) throws IllegalArgumentException {46throw newGetByteIllegalArgumentException();47}4849public char getChar(Object obj) throws IllegalArgumentException {50throw newGetCharIllegalArgumentException();51}5253public short getShort(Object obj) throws IllegalArgumentException {54throw newGetShortIllegalArgumentException();55}5657public int getInt(Object obj) throws IllegalArgumentException {58throw newGetIntIllegalArgumentException();59}6061public long getLong(Object obj) throws IllegalArgumentException {62throw newGetLongIllegalArgumentException();63}6465public float getFloat(Object obj) throws IllegalArgumentException {66throw newGetFloatIllegalArgumentException();67}6869public double getDouble(Object obj) throws IllegalArgumentException {70throw newGetDoubleIllegalArgumentException();71}7273public void set(Object obj, Object value)74throws IllegalArgumentException, IllegalAccessException75{76ensureObj(obj);77if (isReadOnly) {78throwFinalFieldIllegalAccessException(value);79}80if (value != null) {81if (!field.getType().isAssignableFrom(value.getClass())) {82throwSetIllegalArgumentException(value);83}84}85unsafe.putReferenceVolatile(obj, fieldOffset, value);86}8788public void setBoolean(Object obj, boolean z)89throws IllegalArgumentException, IllegalAccessException90{91throwSetIllegalArgumentException(z);92}9394public void setByte(Object obj, byte b)95throws IllegalArgumentException, IllegalAccessException96{97throwSetIllegalArgumentException(b);98}99100public void setChar(Object obj, char c)101throws IllegalArgumentException, IllegalAccessException102{103throwSetIllegalArgumentException(c);104}105106public void setShort(Object obj, short s)107throws IllegalArgumentException, IllegalAccessException108{109throwSetIllegalArgumentException(s);110}111112public void setInt(Object obj, int i)113throws IllegalArgumentException, IllegalAccessException114{115throwSetIllegalArgumentException(i);116}117118public void setLong(Object obj, long l)119throws IllegalArgumentException, IllegalAccessException120{121throwSetIllegalArgumentException(l);122}123124public void setFloat(Object obj, float f)125throws IllegalArgumentException, IllegalAccessException126{127throwSetIllegalArgumentException(f);128}129130public void setDouble(Object obj, double d)131throws IllegalArgumentException, IllegalAccessException132{133throwSetIllegalArgumentException(d);134}135}136137138