Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java @ 21505:f73ffccf4240
[AMD64] Use shorter encoding of zero-extend opcodes.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 27 May 2015 12:23:22 +0200 |
parents | c6ba61a3d05a |
children | 5e868236654f |
rev | line source |
---|---|
15251 | 1 /* |
20173 | 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
15251 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.replacements.test; | |
24 | |
15291
471e28b8f03b
Move UnsafeAccess to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15251
diff
changeset
|
25 import static com.oracle.graal.compiler.common.UnsafeAccess.*; |
15251 | 26 |
27 import org.junit.*; | |
28 | |
29 import sun.misc.*; | |
30 | |
31 import com.oracle.graal.api.code.*; | |
18120
86ec7f6f71b3
refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents:
16714
diff
changeset
|
32 import com.oracle.graal.api.meta.*; |
15251 | 33 import com.oracle.graal.replacements.*; |
34 | |
35 /** | |
36 * Tests the VM independent {@link UnsafeSubstitutions}. | |
37 */ | |
38 public class UnsafeSubstitutionsTest extends MethodSubstitutionTest { | |
39 | |
40 public void testSubstitution(String testMethodName, Class<?> holder, String methodName, Class<?>[] parameterTypes, Object receiver, Object[] args1, Object[] args2) { | |
18120
86ec7f6f71b3
refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents:
16714
diff
changeset
|
41 ResolvedJavaMethod testMethod = getResolvedJavaMethod(testMethodName); |
86ec7f6f71b3
refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents:
16714
diff
changeset
|
42 ResolvedJavaMethod originalMethod = getResolvedJavaMethod(holder, methodName, parameterTypes); |
15251 | 43 |
44 // Force compilation | |
18127
7cefdad149ad
enable a GraalCompilerTest to override how a method is parsed to produce a graph as well as being able to interpose on the method that is parsed/compiled
Doug Simon <doug.simon@oracle.com>
parents:
18120
diff
changeset
|
45 InstalledCode code = getCode(testMethod); |
15251 | 46 assert code != null; |
47 | |
48 // Verify that the original method and the substitution produce the same value | |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
49 Object expected = invokeSafe(originalMethod, receiver, args1); |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
50 Object actual = invokeSafe(testMethod, null, args2); |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
51 assertDeepEquals(expected, actual); |
15251 | 52 |
53 // Verify that the generated code and the original produce the same value | |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
54 expected = invokeSafe(originalMethod, receiver, args1); |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
55 actual = executeVarargsSafe(code, args2); |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
56 assertDeepEquals(expected, actual); |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18127
diff
changeset
|
57 |
15251 | 58 } |
59 | |
60 static long off(Object o, String name) { | |
61 try { | |
62 return unsafe.objectFieldOffset(o.getClass().getDeclaredField(name)); | |
63 } catch (Exception e) { | |
64 Assert.fail(e.toString()); | |
65 return 0L; | |
66 } | |
67 } | |
68 | |
69 static class Foo { | |
70 boolean z; | |
71 byte b; | |
72 short s; | |
73 char c; | |
74 int i; | |
75 long l; | |
76 float f; | |
77 double d; | |
78 Object o; | |
79 } | |
80 | |
81 @Test | |
82 public void testUnsafeSubstitutions() throws Exception { | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
83 test("unsafeCompareAndSwapInt", unsafe, supply(() -> new Foo()), fooOffset("i")); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
84 |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
85 testGraph("unsafeCompareAndSwapInt"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
86 testGraph("unsafeCompareAndSwapLong"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
87 testGraph("unsafeCompareAndSwapObject"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
88 |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
89 testGraph("unsafeGetBoolean"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
90 testGraph("unsafeGetByte"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
91 testGraph("unsafeGetShort"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
92 testGraph("unsafeGetChar"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
93 testGraph("unsafeGetInt"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
94 testGraph("unsafeGetLong"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
95 testGraph("unsafeGetFloat"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
96 testGraph("unsafeGetDouble"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
97 testGraph("unsafeGetObject"); |
15251 | 98 |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
99 testGraph("unsafePutBoolean"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
100 testGraph("unsafePutByte"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
101 testGraph("unsafePutShort"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
102 testGraph("unsafePutChar"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
103 testGraph("unsafePutInt"); |
20173 | 104 testGraph("unsafePutLong"); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
105 testGraph("unsafePutFloat"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
106 testGraph("unsafePutDouble"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
107 testGraph("unsafePutObject"); |
15251 | 108 |
20173 | 109 testGraph("unsafeGetAddress"); |
110 testGraph("unsafePutAddress"); | |
111 | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
112 testGraph("unsafeDirectMemoryRead"); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
113 testGraph("unsafeDirectMemoryWrite"); |
15251 | 114 |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
115 long address = unsafe.allocateMemory(8 * Kind.values().length); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
116 for (Unsafe unsafeArg : new Unsafe[]{unsafe, null}) { |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
117 test("unsafeCompareAndSwapInt", unsafeArg, supply(() -> new Foo()), fooOffset("i")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
118 test("unsafeCompareAndSwapLong", unsafeArg, supply(() -> new Foo()), fooOffset("l")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
119 test("unsafeCompareAndSwapObject", unsafeArg, supply(() -> new Foo()), fooOffset("o")); |
15251 | 120 |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
121 test("unsafeGetBoolean", unsafeArg, supply(() -> new Foo()), fooOffset("z")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
122 test("unsafeGetByte", unsafeArg, supply(() -> new Foo()), fooOffset("b")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
123 test("unsafeGetShort", unsafeArg, supply(() -> new Foo()), fooOffset("s")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
124 test("unsafeGetChar", unsafeArg, supply(() -> new Foo()), fooOffset("c")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
125 test("unsafeGetInt", unsafeArg, supply(() -> new Foo()), fooOffset("i")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
126 test("unsafeGetLong", unsafeArg, supply(() -> new Foo()), fooOffset("l")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
127 test("unsafeGetFloat", unsafeArg, supply(() -> new Foo()), fooOffset("f")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
128 test("unsafeGetDouble", unsafeArg, supply(() -> new Foo()), fooOffset("d")); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
129 test("unsafeGetObject", unsafeArg, supply(() -> new Foo()), fooOffset("o")); |
15251 | 130 |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
131 test("unsafePutBoolean", unsafeArg, supply(() -> new Foo()), fooOffset("z"), true); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
132 test("unsafePutByte", unsafeArg, supply(() -> new Foo()), fooOffset("b"), (byte) 87); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
133 test("unsafePutShort", unsafeArg, supply(() -> new Foo()), fooOffset("s"), (short) -93); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
134 test("unsafePutChar", unsafeArg, supply(() -> new Foo()), fooOffset("c"), 'A'); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
135 test("unsafePutInt", unsafeArg, supply(() -> new Foo()), fooOffset("i"), 42); |
20173 | 136 test("unsafePutLong", unsafeArg, supply(() -> new Foo()), fooOffset("l"), 4711L); |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
137 test("unsafePutFloat", unsafeArg, supply(() -> new Foo()), fooOffset("f"), 58.0F); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
138 test("unsafePutDouble", unsafeArg, supply(() -> new Foo()), fooOffset("d"), -28736.243465D); |
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
139 test("unsafePutObject", unsafeArg, supply(() -> new Foo()), fooOffset("i"), "value1", "value2", "value3"); |
15251 | 140 |
20173 | 141 test("unsafeGetAddress", unsafeArg, address); |
142 test("unsafePutAddress", unsafeArg, address, 0xDEAD_BEEF_DEAD_BABEL); | |
143 | |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
144 test("unsafeDirectMemoryRead", unsafeArg, address); |
20173 | 145 test("unsafeDirectMemoryWrite", unsafeArg, address, 0xCAFE_BABE_DEAD_BABEL); |
19962
9b669776bf8a
added null checking for the receiver when inlining or applying an InvocationPlugin during graph parsing
Doug Simon <doug.simon@oracle.com>
parents:
19791
diff
changeset
|
146 } |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
147 unsafe.freeMemory(address); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
148 } |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
149 |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
150 private static long fooOffset(String name) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
151 try { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
152 return unsafe.objectFieldOffset(Foo.class.getDeclaredField(name)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
153 } catch (NoSuchFieldException | SecurityException e) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
154 throw new AssertionError(e); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
155 } |
15251 | 156 } |
157 | |
158 @SuppressWarnings("all") | |
159 public static boolean unsafeCompareAndSwapInt(Unsafe unsafe, Object obj, long offset) { | |
160 return unsafe.compareAndSwapInt(obj, offset, 0, 1); | |
161 } | |
162 | |
163 @SuppressWarnings("all") | |
164 public static boolean unsafeCompareAndSwapLong(Unsafe unsafe, Object obj, long offset) { | |
165 return unsafe.compareAndSwapLong(obj, offset, 0, 1); | |
166 } | |
167 | |
168 @SuppressWarnings("all") | |
169 public static boolean unsafeCompareAndSwapObject(Unsafe unsafe, Object obj, long offset) { | |
170 return unsafe.compareAndSwapObject(obj, offset, null, new Object()); | |
171 } | |
172 | |
173 @SuppressWarnings("all") | |
174 public static boolean unsafeGetBoolean(Unsafe unsafe, Object obj, long offset) { | |
175 return unsafe.getBoolean(obj, offset) && unsafe.getBooleanVolatile(obj, offset); | |
176 } | |
177 | |
178 @SuppressWarnings("all") | |
179 public static int unsafeGetByte(Unsafe unsafe, Object obj, long offset) { | |
180 return unsafe.getByte(obj, offset) + unsafe.getByteVolatile(obj, offset); | |
181 } | |
182 | |
183 @SuppressWarnings("all") | |
184 public static int unsafeGetShort(Unsafe unsafe, Object obj, long offset) { | |
185 return unsafe.getShort(obj, offset) + unsafe.getShortVolatile(obj, offset); | |
186 } | |
187 | |
188 @SuppressWarnings("all") | |
189 public static int unsafeGetChar(Unsafe unsafe, Object obj, long offset) { | |
190 return unsafe.getChar(obj, offset) + unsafe.getCharVolatile(obj, offset); | |
191 } | |
192 | |
193 @SuppressWarnings("all") | |
194 public static int unsafeGetInt(Unsafe unsafe, Object obj, long offset) { | |
195 return unsafe.getInt(obj, offset) + unsafe.getIntVolatile(obj, offset); | |
196 } | |
197 | |
198 @SuppressWarnings("all") | |
199 public static long unsafeGetLong(Unsafe unsafe, Object obj, long offset) { | |
200 return unsafe.getLong(obj, offset) + unsafe.getLongVolatile(obj, offset); | |
201 } | |
202 | |
203 @SuppressWarnings("all") | |
204 public static float unsafeGetFloat(Unsafe unsafe, Object obj, long offset) { | |
205 return unsafe.getFloat(obj, offset) + unsafe.getFloatVolatile(obj, offset); | |
206 } | |
207 | |
208 @SuppressWarnings("all") | |
209 public static double unsafeGetDouble(Unsafe unsafe, Object obj, long offset) { | |
210 return unsafe.getDouble(obj, offset) + unsafe.getDoubleVolatile(obj, offset); | |
211 } | |
212 | |
213 @SuppressWarnings("all") | |
214 public static boolean unsafeGetObject(Unsafe unsafe, Object obj, long offset) { | |
215 return unsafe.getObject(obj, offset) == unsafe.getObjectVolatile(obj, offset); | |
216 } | |
217 | |
218 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
219 public static int unsafePutBoolean(Unsafe unsafe, Object obj, long offset, boolean value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
220 int res = 1; |
15251 | 221 unsafe.putBoolean(obj, offset, value); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
222 res += unsafe.getBoolean(obj, offset) ? 3 : 5; |
15251 | 223 unsafe.putBooleanVolatile(obj, offset, value); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
224 res += unsafe.getBoolean(obj, offset) ? 7 : 11; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
225 return res; |
15251 | 226 } |
227 | |
228 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
229 public static int unsafePutByte(Unsafe unsafe, Object obj, long offset, byte value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
230 int res = 1; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
231 unsafe.putByte(obj, offset, (byte) (value + 1)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
232 res += unsafe.getByte(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
233 unsafe.putByteVolatile(obj, offset, (byte) (value + 2)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
234 res += unsafe.getByte(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
235 return res; |
15251 | 236 } |
237 | |
238 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
239 public static int unsafePutShort(Unsafe unsafe, Object obj, long offset, short value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
240 int res = 1; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
241 unsafe.putShort(obj, offset, (short) (value + 1)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
242 res += unsafe.getShort(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
243 unsafe.putShortVolatile(obj, offset, (short) (value + 2)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
244 res += unsafe.getShort(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
245 return res; |
15251 | 246 } |
247 | |
248 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
249 public static int unsafePutChar(Unsafe unsafe, Object obj, long offset, char value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
250 int res = 1; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
251 unsafe.putChar(obj, offset, (char) (value + 1)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
252 res += unsafe.getChar(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
253 unsafe.putCharVolatile(obj, offset, (char) (value + 2)); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
254 res += unsafe.getChar(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
255 return res; |
15251 | 256 } |
257 | |
258 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
259 public static int unsafePutInt(Unsafe unsafe, Object obj, long offset, int value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
260 int res = 1; |
15251 | 261 unsafe.putInt(obj, offset, value); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
262 res += unsafe.getInt(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
263 unsafe.putIntVolatile(obj, offset, value + 1); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
264 res += unsafe.getInt(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
265 unsafe.putOrderedInt(obj, offset, value + 2); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
266 res += unsafe.getInt(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
267 return res; |
15251 | 268 } |
269 | |
270 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
271 public static long unsafePutLong(Unsafe unsafe, Object obj, long offset, long value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
272 long res = 1; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
273 unsafe.putLong(obj, offset, value + 1); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
274 res += unsafe.getLong(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
275 unsafe.putLongVolatile(obj, offset, value + 2); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
276 res += unsafe.getLong(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
277 unsafe.putOrderedLong(obj, offset, value + 3); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
278 res += unsafe.getLong(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
279 return res; |
15251 | 280 } |
281 | |
282 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
283 public static float unsafePutFloat(Unsafe unsafe, Object obj, long offset, float value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
284 float res = 1; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
285 unsafe.putFloat(obj, offset, value + 1.0F); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
286 res += unsafe.getFloat(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
287 unsafe.putFloatVolatile(obj, offset, value + 2.0F); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
288 res += unsafe.getFloat(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
289 return res; |
15251 | 290 } |
291 | |
292 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
293 public static double unsafePutDouble(Unsafe unsafe, Object obj, long offset, double value) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
294 double res = 1; |
15251 | 295 unsafe.putDouble(obj, offset, value); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
296 res += unsafe.getDouble(obj, offset); |
15251 | 297 unsafe.putDoubleVolatile(obj, offset, value); |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
298 res += unsafe.getDouble(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
299 return res; |
15251 | 300 } |
301 | |
302 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
303 public static Object[] unsafePutObject(Unsafe unsafe, Object obj, long offset, Object value1, Object value2, Object value3) { |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
304 Object[] res = new Object[3]; |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
305 unsafe.putObject(obj, offset, value1); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
306 res[0] = unsafe.getObject(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
307 unsafe.putObjectVolatile(obj, offset, value2); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
308 res[1] = unsafe.getObject(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
309 unsafe.putOrderedObject(obj, offset, value3); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
310 res[2] = unsafe.getObject(obj, offset); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
311 return res; |
15251 | 312 } |
313 | |
314 @SuppressWarnings("all") | |
20173 | 315 public static long unsafeGetAddress(Unsafe unsafe, long offset) { |
316 return unsafe.getAddress(offset); | |
317 } | |
318 | |
319 @SuppressWarnings("all") | |
320 public static long unsafePutAddress(Unsafe unsafe, long offset, long value) { | |
321 long res = 1; | |
322 unsafe.putAddress(offset, value); | |
323 res += unsafe.getAddress(offset); | |
324 return res; | |
325 } | |
326 | |
327 @SuppressWarnings("all") | |
15251 | 328 public static double unsafeDirectMemoryRead(Unsafe unsafe, long address) { |
329 // Unsafe.getBoolean(long) and Unsafe.getObject(long) do not exist | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
330 // @formatter:off |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
331 return unsafe.getByte(address) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
332 unsafe.getShort(address + 8) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
333 unsafe.getChar(address + 16) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
334 unsafe.getInt(address + 24) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
335 unsafe.getLong(address + 32) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
336 unsafe.getFloat(address + 40) + |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
337 unsafe.getDouble(address + 48); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
338 // @formatter:on |
15251 | 339 } |
340 | |
341 @SuppressWarnings("all") | |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
342 public static double unsafeDirectMemoryWrite(Unsafe unsafe, long address, long value) { |
15251 | 343 // Unsafe.putBoolean(long) and Unsafe.putObject(long) do not exist |
19791
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
344 unsafe.putByte(address + 0, (byte) value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
345 unsafe.putShort(address + 8, (short) value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
346 unsafe.putChar(address + 16, (char) value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
347 unsafe.putInt(address + 24, (int) value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
348 unsafe.putLong(address + 32, value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
349 unsafe.putFloat(address + 40, value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
350 unsafe.putDouble(address + 48, value); |
14e703edb2ab
use GraphBuilderPlugins for method substitutions, intrinsics and snippets (GRAAL-982)
Doug Simon <doug.simon@oracle.com>
parents:
18163
diff
changeset
|
351 return unsafeDirectMemoryRead(unsafe, address); |
15251 | 352 } |
353 | |
354 @Test | |
355 public void testGetAndAddInt() throws Exception { | |
356 Foo f1 = new Foo(); | |
357 Foo f2 = new Foo(); | |
358 long offset = off(f1, "i"); | |
359 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, int.class}; | |
360 for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) { | |
361 Object[] args1 = new Object[]{f1, offset, delta}; | |
362 Object[] args2 = new Object[]{f2, offset, delta}; | |
363 testSubstitution("getAndAddInt", Unsafe.class, "getAndAddInt", parameterTypes, unsafe, args1, args2); | |
364 } | |
365 } | |
366 | |
367 public static int getAndAddInt(Object obj, long offset, int delta) { | |
368 return unsafe.getAndAddInt(obj, offset, delta); | |
369 } | |
370 | |
371 @Test | |
372 public void testGetAndAddLong() throws Exception { | |
373 Foo f1 = new Foo(); | |
374 Foo f2 = new Foo(); | |
375 long offset = off(f1, "l"); | |
376 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, long.class}; | |
377 for (long delta = Long.MAX_VALUE - 10; delta < Long.MAX_VALUE; delta++) { | |
378 Object[] args1 = new Object[]{f1, offset, delta}; | |
379 Object[] args2 = new Object[]{f2, offset, delta}; | |
380 testSubstitution("getAndAddLong", Unsafe.class, "getAndAddLong", parameterTypes, unsafe, args1, args2); | |
381 } | |
382 } | |
383 | |
384 public static long getAndAddLong(Object obj, long offset, long delta) { | |
385 return unsafe.getAndAddLong(obj, offset, delta); | |
386 } | |
387 | |
388 @Test | |
389 public void testGetAndSetInt() throws Exception { | |
390 Foo f1 = new Foo(); | |
391 Foo f2 = new Foo(); | |
392 long offset = off(f1, "i"); | |
393 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, int.class}; | |
394 for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) { | |
395 Object[] args1 = new Object[]{f1, offset, delta}; | |
396 Object[] args2 = new Object[]{f2, offset, delta}; | |
397 testSubstitution("getAndSetInt", Unsafe.class, "getAndSetInt", parameterTypes, unsafe, args1, args2); | |
398 } | |
399 } | |
400 | |
401 public static int getAndSetInt(Object obj, long offset, int newValue) { | |
402 return unsafe.getAndSetInt(obj, offset, newValue); | |
403 } | |
404 | |
405 @Test | |
406 public void testGetAndSetLong() throws Exception { | |
407 Foo f1 = new Foo(); | |
408 Foo f2 = new Foo(); | |
409 long offset = off(f1, "l"); | |
410 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, long.class}; | |
411 for (long newValue = Long.MAX_VALUE - 10; newValue < Long.MAX_VALUE; newValue++) { | |
412 Object[] args1 = new Object[]{f1, offset, newValue}; | |
413 Object[] args2 = new Object[]{f2, offset, newValue}; | |
414 testSubstitution("getAndSetLong", Unsafe.class, "getAndSetLong", parameterTypes, unsafe, args1, args2); | |
415 } | |
416 } | |
417 | |
418 public static long getAndSetLong(Object obj, long offset, long newValue) { | |
419 return unsafe.getAndSetLong(obj, offset, newValue); | |
420 } | |
421 | |
422 @Test | |
423 public void testGetAndSetObject() throws Exception { | |
424 Foo f1 = new Foo(); | |
425 Foo f2 = new Foo(); | |
426 long offset = off(f1, "o"); | |
427 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, Object.class}; | |
428 for (long i = 0; i < 10; i++) { | |
429 Object o = new Object(); | |
430 Object[] args1 = new Object[]{f1, offset, o}; | |
431 Object[] args2 = new Object[]{f2, offset, o}; | |
432 testSubstitution("getAndSetObject", Unsafe.class, "getAndSetObject", parameterTypes, unsafe, args1, args2); | |
433 System.gc(); | |
434 } | |
435 } | |
436 | |
437 public static Object getAndSetObject(Object obj, long offset, Object newValue) { | |
438 return unsafe.getAndSetObject(obj, offset, newValue); | |
439 } | |
440 | |
441 } |