Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedIntegerFieldAccessorImpl.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 UnsafeQualifiedIntegerFieldAccessorImpl30extends UnsafeQualifiedFieldAccessorImpl31{32UnsafeQualifiedIntegerFieldAccessorImpl(Field field, boolean isReadOnly) {33super(field, isReadOnly);34}3536public Object get(Object obj) throws IllegalArgumentException {37return Integer.valueOf(getInt(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 {57ensureObj(obj);58return unsafe.getIntVolatile(obj, fieldOffset);59}6061public long getLong(Object obj) throws IllegalArgumentException {62return getInt(obj);63}6465public float getFloat(Object obj) throws IllegalArgumentException {66return getInt(obj);67}6869public double getDouble(Object obj) throws IllegalArgumentException {70return getInt(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.putIntVolatile(obj, fieldOffset, ((Byte) value).byteValue());85return;86}87if (value instanceof Short) {88unsafe.putIntVolatile(obj, fieldOffset, ((Short) value).shortValue());89return;90}91if (value instanceof Character) {92unsafe.putIntVolatile(obj, fieldOffset, ((Character) value).charValue());93return;94}95if (value instanceof Integer) {96unsafe.putIntVolatile(obj, fieldOffset, ((Integer) value).intValue());97return;98}99throwSetIllegalArgumentException(value);100}101102public void setBoolean(Object obj, boolean z)103throws IllegalArgumentException, IllegalAccessException104{105throwSetIllegalArgumentException(z);106}107108public void setByte(Object obj, byte b)109throws IllegalArgumentException, IllegalAccessException110{111setInt(obj, b);112}113114public void setChar(Object obj, char c)115throws IllegalArgumentException, IllegalAccessException116{117setInt(obj, c);118}119120public void setShort(Object obj, short s)121throws IllegalArgumentException, IllegalAccessException122{123setInt(obj, s);124}125126public void setInt(Object obj, int i)127throws IllegalArgumentException, IllegalAccessException128{129ensureObj(obj);130if (isReadOnly) {131throwFinalFieldIllegalAccessException(i);132}133unsafe.putIntVolatile(obj, fieldOffset, i);134}135136public void setLong(Object obj, long l)137throws IllegalArgumentException, IllegalAccessException138{139throwSetIllegalArgumentException(l);140}141142public void setFloat(Object obj, float f)143throws IllegalArgumentException, IllegalAccessException144{145throwSetIllegalArgumentException(f);146}147148public void setDouble(Object obj, double d)149throws IllegalArgumentException, IllegalAccessException150{151throwSetIllegalArgumentException(d);152}153}154155156