1 /* 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.misc; 27 28 import dalvik.annotation.compat.UnsupportedAppUsage; 29 import dalvik.system.VersionCodes; 30 31 @SuppressWarnings({"unchecked", "deprecation", "all"}) 32 public final class Unsafe { 33 Unsafe()34 private Unsafe() { 35 throw new RuntimeException("Stub!"); 36 } 37 38 @UnsupportedAppUsage getUnsafe()39 public static sun.misc.Unsafe getUnsafe() { 40 throw new RuntimeException("Stub!"); 41 } 42 43 @UnsupportedAppUsage objectFieldOffset(java.lang.reflect.Field field)44 public long objectFieldOffset(java.lang.reflect.Field field) { 45 throw new RuntimeException("Stub!"); 46 } 47 48 @UnsupportedAppUsage arrayBaseOffset(java.lang.Class clazz)49 public int arrayBaseOffset(java.lang.Class clazz) { 50 throw new RuntimeException("Stub!"); 51 } 52 53 @UnsupportedAppUsage arrayIndexScale(java.lang.Class clazz)54 public int arrayIndexScale(java.lang.Class clazz) { 55 throw new RuntimeException("Stub!"); 56 } 57 58 @UnsupportedAppUsage(maxTargetSdk = VersionCodes.O) getArrayBaseOffsetForComponentType(java.lang.Class component_class)59 private static native int getArrayBaseOffsetForComponentType(java.lang.Class component_class); 60 61 @UnsupportedAppUsage(maxTargetSdk = VersionCodes.O) getArrayIndexScaleForComponentType(java.lang.Class component_class)62 private static native int getArrayIndexScaleForComponentType(java.lang.Class component_class); 63 64 @UnsupportedAppUsage compareAndSwapInt( java.lang.Object obj, long offset, int expectedValue, int newValue)65 public native boolean compareAndSwapInt( 66 java.lang.Object obj, long offset, int expectedValue, int newValue); 67 68 @UnsupportedAppUsage compareAndSwapLong( java.lang.Object obj, long offset, long expectedValue, long newValue)69 public native boolean compareAndSwapLong( 70 java.lang.Object obj, long offset, long expectedValue, long newValue); 71 72 @UnsupportedAppUsage compareAndSwapObject( java.lang.Object obj, long offset, java.lang.Object expectedValue, java.lang.Object newValue)73 public native boolean compareAndSwapObject( 74 java.lang.Object obj, 75 long offset, 76 java.lang.Object expectedValue, 77 java.lang.Object newValue); 78 79 @UnsupportedAppUsage getIntVolatile(java.lang.Object obj, long offset)80 public native int getIntVolatile(java.lang.Object obj, long offset); 81 82 @UnsupportedAppUsage putIntVolatile(java.lang.Object obj, long offset, int newValue)83 public native void putIntVolatile(java.lang.Object obj, long offset, int newValue); 84 85 @UnsupportedAppUsage getLongVolatile(java.lang.Object obj, long offset)86 public native long getLongVolatile(java.lang.Object obj, long offset); 87 88 @UnsupportedAppUsage putLongVolatile(java.lang.Object obj, long offset, long newValue)89 public native void putLongVolatile(java.lang.Object obj, long offset, long newValue); 90 91 @UnsupportedAppUsage getObjectVolatile(java.lang.Object obj, long offset)92 public native java.lang.Object getObjectVolatile(java.lang.Object obj, long offset); 93 94 @UnsupportedAppUsage putObjectVolatile( java.lang.Object obj, long offset, java.lang.Object newValue)95 public native void putObjectVolatile( 96 java.lang.Object obj, long offset, java.lang.Object newValue); 97 98 @UnsupportedAppUsage getInt(java.lang.Object obj, long offset)99 public native int getInt(java.lang.Object obj, long offset); 100 101 @UnsupportedAppUsage putInt(java.lang.Object obj, long offset, int newValue)102 public native void putInt(java.lang.Object obj, long offset, int newValue); 103 104 @UnsupportedAppUsage putOrderedInt(java.lang.Object obj, long offset, int newValue)105 public native void putOrderedInt(java.lang.Object obj, long offset, int newValue); 106 107 @UnsupportedAppUsage getLong(java.lang.Object obj, long offset)108 public native long getLong(java.lang.Object obj, long offset); 109 110 @UnsupportedAppUsage putLong(java.lang.Object obj, long offset, long newValue)111 public native void putLong(java.lang.Object obj, long offset, long newValue); 112 113 @UnsupportedAppUsage putOrderedLong(java.lang.Object obj, long offset, long newValue)114 public native void putOrderedLong(java.lang.Object obj, long offset, long newValue); 115 116 @UnsupportedAppUsage getObject(java.lang.Object obj, long offset)117 public native java.lang.Object getObject(java.lang.Object obj, long offset); 118 119 @UnsupportedAppUsage putObject(java.lang.Object obj, long offset, java.lang.Object newValue)120 public native void putObject(java.lang.Object obj, long offset, java.lang.Object newValue); 121 122 @UnsupportedAppUsage putOrderedObject( java.lang.Object obj, long offset, java.lang.Object newValue)123 public native void putOrderedObject( 124 java.lang.Object obj, long offset, java.lang.Object newValue); 125 126 @UnsupportedAppUsage getBoolean(java.lang.Object obj, long offset)127 public native boolean getBoolean(java.lang.Object obj, long offset); 128 129 @UnsupportedAppUsage putBoolean(java.lang.Object obj, long offset, boolean newValue)130 public native void putBoolean(java.lang.Object obj, long offset, boolean newValue); 131 132 @UnsupportedAppUsage getByte(java.lang.Object obj, long offset)133 public native byte getByte(java.lang.Object obj, long offset); 134 135 @UnsupportedAppUsage putByte(java.lang.Object obj, long offset, byte newValue)136 public native void putByte(java.lang.Object obj, long offset, byte newValue); 137 138 @UnsupportedAppUsage getChar(java.lang.Object obj, long offset)139 public native char getChar(java.lang.Object obj, long offset); 140 141 @UnsupportedAppUsage putChar(java.lang.Object obj, long offset, char newValue)142 public native void putChar(java.lang.Object obj, long offset, char newValue); 143 144 @UnsupportedAppUsage getShort(java.lang.Object obj, long offset)145 public native short getShort(java.lang.Object obj, long offset); 146 147 @UnsupportedAppUsage putShort(java.lang.Object obj, long offset, short newValue)148 public native void putShort(java.lang.Object obj, long offset, short newValue); 149 150 @UnsupportedAppUsage getFloat(java.lang.Object obj, long offset)151 public native float getFloat(java.lang.Object obj, long offset); 152 153 @UnsupportedAppUsage putFloat(java.lang.Object obj, long offset, float newValue)154 public native void putFloat(java.lang.Object obj, long offset, float newValue); 155 156 @UnsupportedAppUsage getDouble(java.lang.Object obj, long offset)157 public native double getDouble(java.lang.Object obj, long offset); 158 159 @UnsupportedAppUsage putDouble(java.lang.Object obj, long offset, double newValue)160 public native void putDouble(java.lang.Object obj, long offset, double newValue); 161 162 @UnsupportedAppUsage park(boolean absolute, long time)163 public void park(boolean absolute, long time) { 164 throw new RuntimeException("Stub!"); 165 } 166 167 @UnsupportedAppUsage unpark(java.lang.Object obj)168 public void unpark(java.lang.Object obj) { 169 throw new RuntimeException("Stub!"); 170 } 171 172 @UnsupportedAppUsage allocateInstance(java.lang.Class<?> c)173 public native java.lang.Object allocateInstance(java.lang.Class<?> c); 174 175 @UnsupportedAppUsage addressSize()176 public native int addressSize(); 177 178 @UnsupportedAppUsage pageSize()179 public native int pageSize(); 180 181 @UnsupportedAppUsage allocateMemory(long bytes)182 public native long allocateMemory(long bytes); 183 184 @UnsupportedAppUsage freeMemory(long address)185 public native void freeMemory(long address); 186 187 @UnsupportedAppUsage setMemory(long address, long bytes, byte value)188 public native void setMemory(long address, long bytes, byte value); 189 190 @UnsupportedAppUsage getByte(long address)191 public native byte getByte(long address); 192 193 @UnsupportedAppUsage putByte(long address, byte x)194 public native void putByte(long address, byte x); 195 196 @UnsupportedAppUsage getShort(long address)197 public native short getShort(long address); 198 199 @UnsupportedAppUsage putShort(long address, short x)200 public native void putShort(long address, short x); 201 202 @UnsupportedAppUsage getChar(long address)203 public native char getChar(long address); 204 205 @UnsupportedAppUsage putChar(long address, char x)206 public native void putChar(long address, char x); 207 208 @UnsupportedAppUsage getInt(long address)209 public native int getInt(long address); 210 211 @UnsupportedAppUsage putInt(long address, int x)212 public native void putInt(long address, int x); 213 214 @UnsupportedAppUsage getLong(long address)215 public native long getLong(long address); 216 217 @UnsupportedAppUsage putLong(long address, long x)218 public native void putLong(long address, long x); 219 220 @UnsupportedAppUsage getFloat(long address)221 public native float getFloat(long address); 222 223 @UnsupportedAppUsage putFloat(long address, float x)224 public native void putFloat(long address, float x); 225 226 @UnsupportedAppUsage getDouble(long address)227 public native double getDouble(long address); 228 229 @UnsupportedAppUsage putDouble(long address, double x)230 public native void putDouble(long address, double x); 231 232 @UnsupportedAppUsage copyMemoryToPrimitiveArray( long srcAddr, java.lang.Object dst, long dstOffset, long bytes)233 public native void copyMemoryToPrimitiveArray( 234 long srcAddr, java.lang.Object dst, long dstOffset, long bytes); 235 236 @UnsupportedAppUsage copyMemoryFromPrimitiveArray( java.lang.Object src, long srcOffset, long dstAddr, long bytes)237 public native void copyMemoryFromPrimitiveArray( 238 java.lang.Object src, long srcOffset, long dstAddr, long bytes); 239 240 @UnsupportedAppUsage copyMemory(long srcAddr, long dstAddr, long bytes)241 public native void copyMemory(long srcAddr, long dstAddr, long bytes); 242 243 @UnsupportedAppUsage getAndAddInt(java.lang.Object o, long offset, int delta)244 public int getAndAddInt(java.lang.Object o, long offset, int delta) { 245 throw new RuntimeException("Stub!"); 246 } 247 248 @UnsupportedAppUsage getAndAddLong(java.lang.Object o, long offset, long delta)249 public long getAndAddLong(java.lang.Object o, long offset, long delta) { 250 throw new RuntimeException("Stub!"); 251 } 252 253 @UnsupportedAppUsage getAndSetInt(java.lang.Object o, long offset, int newValue)254 public int getAndSetInt(java.lang.Object o, long offset, int newValue) { 255 throw new RuntimeException("Stub!"); 256 } 257 258 @UnsupportedAppUsage getAndSetLong(java.lang.Object o, long offset, long newValue)259 public long getAndSetLong(java.lang.Object o, long offset, long newValue) { 260 throw new RuntimeException("Stub!"); 261 } 262 263 @UnsupportedAppUsage getAndSetObject( java.lang.Object o, long offset, java.lang.Object newValue)264 public java.lang.Object getAndSetObject( 265 java.lang.Object o, long offset, java.lang.Object newValue) { 266 throw new RuntimeException("Stub!"); 267 } 268 269 @UnsupportedAppUsage loadFence()270 public native void loadFence(); 271 272 @UnsupportedAppUsage storeFence()273 public native void storeFence(); 274 275 @UnsupportedAppUsage fullFence()276 public native void fullFence(); 277 278 @UnsupportedAppUsage 279 public static final int INVALID_FIELD_OFFSET = -1; // 0xffffffff 280 281 @UnsupportedAppUsage private static final sun.misc.Unsafe THE_ONE; 282 283 static { 284 THE_ONE = null; 285 } 286 287 @UnsupportedAppUsage private static final sun.misc.Unsafe theUnsafe; 288 289 static { 290 theUnsafe = null; 291 } 292 } 293