Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeLongFieldAccessorImpl.java
41159 views
/*1* Copyright (c) 2001, 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 UnsafeLongFieldAccessorImpl extends UnsafeFieldAccessorImpl {30UnsafeLongFieldAccessorImpl(Field field) {31super(field);32}3334public Object get(Object obj) throws IllegalArgumentException {35return Long.valueOf(getLong(obj));36}3738public boolean getBoolean(Object obj) throws IllegalArgumentException {39throw newGetBooleanIllegalArgumentException();40}4142public byte getByte(Object obj) throws IllegalArgumentException {43throw newGetByteIllegalArgumentException();44}4546public char getChar(Object obj) throws IllegalArgumentException {47throw newGetCharIllegalArgumentException();48}4950public short getShort(Object obj) throws IllegalArgumentException {51throw newGetShortIllegalArgumentException();52}5354public int getInt(Object obj) throws IllegalArgumentException {55throw newGetIntIllegalArgumentException();56}5758public long getLong(Object obj) throws IllegalArgumentException {59ensureObj(obj);60return unsafe.getLong(obj, fieldOffset);61}6263public float getFloat(Object obj) throws IllegalArgumentException {64return getLong(obj);65}6667public double getDouble(Object obj) throws IllegalArgumentException {68return getLong(obj);69}7071public void set(Object obj, Object value)72throws IllegalArgumentException, IllegalAccessException73{74ensureObj(obj);75if (isFinal) {76throwFinalFieldIllegalAccessException(value);77}78if (value == null) {79throwSetIllegalArgumentException(value);80}81if (value instanceof Byte) {82unsafe.putLong(obj, fieldOffset, ((Byte) value).byteValue());83return;84}85if (value instanceof Short) {86unsafe.putLong(obj, fieldOffset, ((Short) value).shortValue());87return;88}89if (value instanceof Character) {90unsafe.putLong(obj, fieldOffset, ((Character) value).charValue());91return;92}93if (value instanceof Integer) {94unsafe.putLong(obj, fieldOffset, ((Integer) value).intValue());95return;96}97if (value instanceof Long) {98unsafe.putLong(obj, fieldOffset, ((Long) value).longValue());99return;100}101throwSetIllegalArgumentException(value);102}103104public void setBoolean(Object obj, boolean z)105throws IllegalArgumentException, IllegalAccessException106{107throwSetIllegalArgumentException(z);108}109110public void setByte(Object obj, byte b)111throws IllegalArgumentException, IllegalAccessException112{113setLong(obj, b);114}115116public void setChar(Object obj, char c)117throws IllegalArgumentException, IllegalAccessException118{119setLong(obj, c);120}121122public void setShort(Object obj, short s)123throws IllegalArgumentException, IllegalAccessException124{125setLong(obj, s);126}127128public void setInt(Object obj, int i)129throws IllegalArgumentException, IllegalAccessException130{131setLong(obj, i);132}133134public void setLong(Object obj, long l)135throws IllegalArgumentException, IllegalAccessException136{137ensureObj(obj);138if (isFinal) {139throwFinalFieldIllegalAccessException(l);140}141unsafe.putLong(obj, fieldOffset, l);142}143144public void setFloat(Object obj, float f)145throws IllegalArgumentException, IllegalAccessException146{147throwSetIllegalArgumentException(f);148}149150public void setDouble(Object obj, double d)151throws IllegalArgumentException, IllegalAccessException152{153throwSetIllegalArgumentException(d);154}155}156157158