RFR: add getAddress/putAddress to Unsafe plugin

Christian Thalinger christian.thalinger at oracle.com
Mon Apr 6 16:21:40 UTC 2015


Thanks, pushing.

> On Apr 5, 2015, at 12:44 AM, Doug Simon <doug.simon at oracle.com> wrote:
> 
> Looks good to me.
> 
>> On Apr 5, 2015, at 5:37 AM, Christian Thalinger <christian.thalinger at oracle.com> wrote:
>> 
>> Sure.  Also, I noticed that unsafePutLong isn’t tested so I added it too:
>> 
>> diff -r 6adad2a0a24d graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java
>> --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java	Fri Apr 03 17:49:43 2015 +0200
>> +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java	Sat Apr 04 20:35:43 2015 -0700
>> @@ -101,10 +101,14 @@ public class UnsafeSubstitutionsTest ext
>>        testGraph("unsafePutShort");
>>        testGraph("unsafePutChar");
>>        testGraph("unsafePutInt");
>> +        testGraph("unsafePutLong");
>>        testGraph("unsafePutFloat");
>>        testGraph("unsafePutDouble");
>>        testGraph("unsafePutObject");
>> 
>> +        testGraph("unsafeGetAddress");
>> +        testGraph("unsafePutAddress");
>> +
>>        testGraph("unsafeDirectMemoryRead");
>>        testGraph("unsafeDirectMemoryWrite");
>> 
>> @@ -129,12 +133,16 @@ public class UnsafeSubstitutionsTest ext
>>            test("unsafePutShort", unsafeArg, supply(() -> new Foo()), fooOffset("s"), (short) -93);
>>            test("unsafePutChar", unsafeArg, supply(() -> new Foo()), fooOffset("c"), 'A');
>>            test("unsafePutInt", unsafeArg, supply(() -> new Foo()), fooOffset("i"), 42);
>> +            test("unsafePutLong", unsafeArg, supply(() -> new Foo()), fooOffset("l"), 4711L);
>>            test("unsafePutFloat", unsafeArg, supply(() -> new Foo()), fooOffset("f"), 58.0F);
>>            test("unsafePutDouble", unsafeArg, supply(() -> new Foo()), fooOffset("d"), -28736.243465D);
>>            test("unsafePutObject", unsafeArg, supply(() -> new Foo()), fooOffset("i"), "value1", "value2", "value3");
>> 
>> +            test("unsafeGetAddress", unsafeArg, address);
>> +            test("unsafePutAddress", unsafeArg, address, 0xDEAD_BEEF_DEAD_BABEL);
>> +
>>            test("unsafeDirectMemoryRead", unsafeArg, address);
>> -            test("unsafeDirectMemoryWrite", unsafeArg, address, 0xCAFEBABEDEADBABEL);
>> +            test("unsafeDirectMemoryWrite", unsafeArg, address, 0xCAFE_BABE_DEAD_BABEL);
>>        }
>>        unsafe.freeMemory(address);
>>    }
>> @@ -304,6 +312,19 @@ public class UnsafeSubstitutionsTest ext
>>    }
>> 
>>    @SuppressWarnings("all")
>> +    public static long unsafeGetAddress(Unsafe unsafe, long offset) {
>> +        return unsafe.getAddress(offset);
>> +    }
>> +
>> +    @SuppressWarnings("all")
>> +    public static long unsafePutAddress(Unsafe unsafe, long offset, long value) {
>> +        long res = 1;
>> +        unsafe.putAddress(offset, value);
>> +        res += unsafe.getAddress(offset);
>> +        return res;
>> +    }
>> +
>> +    @SuppressWarnings("all")
>>    public static double unsafeDirectMemoryRead(Unsafe unsafe, long address) {
>>        // Unsafe.getBoolean(long) and Unsafe.getObject(long) do not exist
>>        // @formatter:off
>> 
>>> On Apr 4, 2015, at 3:59 AM, Doug Simon <doug.simon at oracle.com> wrote:
>>> 
>>> Looks good. Can you please also add tests for these methods to UnsafeSubstitutionsTest?
>>> 
>>>> On Apr 3, 2015, at 10:47 PM, Christian Thalinger <christian.thalinger at oracle.com> wrote:
>>>> 
>>>> getAddress and putAddress are missing:
>>>> 
>>>> diff -r 6adad2a0a24d graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java
>>>> --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Fri Apr 03 17:49:43 2015 +0200
>>>> +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Fri Apr 03 13:45:34 2015 -0700
>>>> @@ -104,6 +104,10 @@ public class StandardGraphBuilderPlugins
>>>>          }
>>>>      }
>>>> 
>>>> +        // Accesses to native memory addresses.
>>>> +        r.register2("getAddress", Receiver.class, long.class, new UnsafeGetPlugin(Kind.Long, false));
>>>> +        r.register3("putAddress", Receiver.class, long.class, long.class, new UnsafePutPlugin(Kind.Long, false));
>>>> +
>>>>      for (Kind kind : new Kind[]{Kind.Int, Kind.Long, Kind.Object}) {
>>>>          Class<?> javaClass = kind == Kind.Object ? Object.class : kind.toJavaClass();
>>>>          r.register5("compareAndSwap" + kind.name(), Receiver.class, Object.class, long.class, javaClass, javaClass, new InvocationPlugin() {
>>>> 
>>> 
>> 
> 



More information about the graal-dev mailing list