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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15251
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
1 /*
20173
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
15251
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
4 *
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
8 *
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
13 * accompanied this code).
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
14 *
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
18 *
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
21 * questions.
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
22 */
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
23 package com.oracle.graal.replacements.test;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
26
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
27 import org.junit.*;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
28
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
29 import sun.misc.*;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
30
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
33 import com.oracle.graal.replacements.*;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
34
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
35 /**
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
36 * Tests the VM independent {@link UnsafeSubstitutions}.
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
37 */
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
38 public class UnsafeSubstitutionsTest extends MethodSubstitutionTest {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
39
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
43
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
46 assert code != null;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
47
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
52
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
58 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
59
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
60 static long off(Object o, String name) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
61 try {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
62 return unsafe.objectFieldOffset(o.getClass().getDeclaredField(name));
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
63 } catch (Exception e) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
64 Assert.fail(e.toString());
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
65 return 0L;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
66 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
67 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
68
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
69 static class Foo {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
70 boolean z;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
71 byte b;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
72 short s;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
73 char c;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
74 int i;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
75 long l;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
76 float f;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
77 double d;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
78 Object o;
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
79 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
80
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
81 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
108
20173
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
109 testGraph("unsafeGetAddress");
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
110 testGraph("unsafePutAddress");
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
140
20173
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
141 test("unsafeGetAddress", unsafeArg, address);
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
142 test("unsafePutAddress", unsafeArg, address, 0xDEAD_BEEF_DEAD_BABEL);
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
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
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
156 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
157
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
158 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
159 public static boolean unsafeCompareAndSwapInt(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
160 return unsafe.compareAndSwapInt(obj, offset, 0, 1);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
161 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
162
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
163 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
164 public static boolean unsafeCompareAndSwapLong(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
165 return unsafe.compareAndSwapLong(obj, offset, 0, 1);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
166 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
167
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
168 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
169 public static boolean unsafeCompareAndSwapObject(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
170 return unsafe.compareAndSwapObject(obj, offset, null, new Object());
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
171 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
172
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
173 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
174 public static boolean unsafeGetBoolean(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
175 return unsafe.getBoolean(obj, offset) && unsafe.getBooleanVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
176 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
177
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
178 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
179 public static int unsafeGetByte(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
180 return unsafe.getByte(obj, offset) + unsafe.getByteVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
181 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
182
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
183 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
184 public static int unsafeGetShort(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
185 return unsafe.getShort(obj, offset) + unsafe.getShortVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
186 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
187
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
188 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
189 public static int unsafeGetChar(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
190 return unsafe.getChar(obj, offset) + unsafe.getCharVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
191 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
192
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
193 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
194 public static int unsafeGetInt(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
195 return unsafe.getInt(obj, offset) + unsafe.getIntVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
196 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
197
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
198 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
199 public static long unsafeGetLong(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
200 return unsafe.getLong(obj, offset) + unsafe.getLongVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
201 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
202
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
203 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
204 public static float unsafeGetFloat(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
205 return unsafe.getFloat(obj, offset) + unsafe.getFloatVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
206 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
207
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
208 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
209 public static double unsafeGetDouble(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
210 return unsafe.getDouble(obj, offset) + unsafe.getDoubleVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
211 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
212
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
213 @SuppressWarnings("all")
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
214 public static boolean unsafeGetObject(Unsafe unsafe, Object obj, long offset) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
215 return unsafe.getObject(obj, offset) == unsafe.getObjectVolatile(obj, offset);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
216 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
217
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
226 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
227
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
236 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
237
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
246 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
247
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
256 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
257
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
268 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
269
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
280 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
281
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
290 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
291
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
300 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
301
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
312 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
313
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
314 @SuppressWarnings("all")
20173
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
315 public static long unsafeGetAddress(Unsafe unsafe, long offset) {
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
316 return unsafe.getAddress(offset);
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
317 }
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
318
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
319 @SuppressWarnings("all")
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
320 public static long unsafePutAddress(Unsafe unsafe, long offset, long value) {
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
321 long res = 1;
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
322 unsafe.putAddress(offset, value);
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
323 res += unsafe.getAddress(offset);
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
324 return res;
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
325 }
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
326
c6ba61a3d05a Add getAddress/putAddress to Unsafe plugin.
twisti
parents: 19983
diff changeset
327 @SuppressWarnings("all")
15251
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
328 public static double unsafeDirectMemoryRead(Unsafe unsafe, long address) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
339 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
340
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
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
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
352 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
353
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
354 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
355 public void testGetAndAddInt() throws Exception {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
356 Foo f1 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
357 Foo f2 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
358 long offset = off(f1, "i");
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
359 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, int.class};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
360 for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
361 Object[] args1 = new Object[]{f1, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
362 Object[] args2 = new Object[]{f2, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
363 testSubstitution("getAndAddInt", Unsafe.class, "getAndAddInt", parameterTypes, unsafe, args1, args2);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
364 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
365 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
366
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
367 public static int getAndAddInt(Object obj, long offset, int delta) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
368 return unsafe.getAndAddInt(obj, offset, delta);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
369 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
370
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
371 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
372 public void testGetAndAddLong() throws Exception {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
373 Foo f1 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
374 Foo f2 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
375 long offset = off(f1, "l");
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
376 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, long.class};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
377 for (long delta = Long.MAX_VALUE - 10; delta < Long.MAX_VALUE; delta++) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
378 Object[] args1 = new Object[]{f1, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
379 Object[] args2 = new Object[]{f2, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
380 testSubstitution("getAndAddLong", Unsafe.class, "getAndAddLong", parameterTypes, unsafe, args1, args2);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
381 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
382 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
383
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
384 public static long getAndAddLong(Object obj, long offset, long delta) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
385 return unsafe.getAndAddLong(obj, offset, delta);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
386 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
387
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
388 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
389 public void testGetAndSetInt() throws Exception {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
390 Foo f1 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
391 Foo f2 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
392 long offset = off(f1, "i");
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
393 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, int.class};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
394 for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
395 Object[] args1 = new Object[]{f1, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
396 Object[] args2 = new Object[]{f2, offset, delta};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
397 testSubstitution("getAndSetInt", Unsafe.class, "getAndSetInt", parameterTypes, unsafe, args1, args2);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
398 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
399 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
400
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
401 public static int getAndSetInt(Object obj, long offset, int newValue) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
402 return unsafe.getAndSetInt(obj, offset, newValue);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
403 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
404
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
405 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
406 public void testGetAndSetLong() throws Exception {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
407 Foo f1 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
408 Foo f2 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
409 long offset = off(f1, "l");
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
410 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, long.class};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
411 for (long newValue = Long.MAX_VALUE - 10; newValue < Long.MAX_VALUE; newValue++) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
412 Object[] args1 = new Object[]{f1, offset, newValue};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
413 Object[] args2 = new Object[]{f2, offset, newValue};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
414 testSubstitution("getAndSetLong", Unsafe.class, "getAndSetLong", parameterTypes, unsafe, args1, args2);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
415 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
416 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
417
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
418 public static long getAndSetLong(Object obj, long offset, long newValue) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
419 return unsafe.getAndSetLong(obj, offset, newValue);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
420 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
421
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
422 @Test
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
423 public void testGetAndSetObject() throws Exception {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
424 Foo f1 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
425 Foo f2 = new Foo();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
426 long offset = off(f1, "o");
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
427 Class<?>[] parameterTypes = new Class<?>[]{Object.class, long.class, Object.class};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
428 for (long i = 0; i < 10; i++) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
429 Object o = new Object();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
430 Object[] args1 = new Object[]{f1, offset, o};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
431 Object[] args2 = new Object[]{f2, offset, o};
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
432 testSubstitution("getAndSetObject", Unsafe.class, "getAndSetObject", parameterTypes, unsafe, args1, args2);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
433 System.gc();
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
434 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
435 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
436
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
437 public static Object getAndSetObject(Object obj, long offset, Object newValue) {
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
438 return unsafe.getAndSetObject(obj, offset, newValue);
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
439 }
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
440
de1d50c121cd Unsafe.getAndAdd/Set method substitutions
twisti
parents:
diff changeset
441 }