comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/UnsafeAccessFactoryImpl.java @ 19311:b54b548047ac

Truffle: also offer UnsafeAccessFactory in DefaultTruffleRuntime
author Andreas Woess <andreas.woess@jku.at>
date Thu, 12 Feb 2015 03:42:51 +0100
parents
children
comparison
equal deleted inserted replaced
19310:3b2fd35f41b0 19311:b54b548047ac
1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.impl;
26
27 import sun.misc.*;
28
29 import com.oracle.truffle.api.unsafe.*;
30
31 final class UnsafeAccessFactoryImpl implements UnsafeAccessFactory {
32 public UnsafeAccess createUnsafeAccess(final Unsafe unsafe) {
33 return new UnsafeAccessImpl(unsafe);
34 }
35
36 private static final class UnsafeAccessImpl implements UnsafeAccess {
37 private final Unsafe unsafe;
38
39 private UnsafeAccessImpl(Unsafe unsafe) {
40 this.unsafe = unsafe;
41 }
42
43 @SuppressWarnings("unchecked")
44 public <T> T uncheckedCast(Object value, Class<T> type, boolean condition, boolean nonNull) {
45 return (T) value;
46 }
47
48 public void putShort(Object receiver, long offset, short value, Object locationIdentity) {
49 unsafe.putShort(receiver, offset, value);
50 }
51
52 public void putObject(Object receiver, long offset, Object value, Object locationIdentity) {
53 unsafe.putObject(receiver, offset, value);
54 }
55
56 public void putLong(Object receiver, long offset, long value, Object locationIdentity) {
57 unsafe.putLong(receiver, offset, value);
58 }
59
60 public void putInt(Object receiver, long offset, int value, Object locationIdentity) {
61 unsafe.putInt(receiver, offset, value);
62 }
63
64 public void putFloat(Object receiver, long offset, float value, Object locationIdentity) {
65 unsafe.putFloat(receiver, offset, value);
66 }
67
68 public void putDouble(Object receiver, long offset, double value, Object locationIdentity) {
69 unsafe.putDouble(receiver, offset, value);
70 }
71
72 public void putByte(Object receiver, long offset, byte value, Object locationIdentity) {
73 unsafe.putByte(receiver, offset, value);
74 }
75
76 public void putBoolean(Object receiver, long offset, boolean value, Object locationIdentity) {
77 unsafe.putBoolean(receiver, offset, value);
78 }
79
80 public short getShort(Object receiver, long offset, boolean condition, Object locationIdentity) {
81 return unsafe.getShort(receiver, offset);
82 }
83
84 public Object getObject(Object receiver, long offset, boolean condition, Object locationIdentity) {
85 return unsafe.getObject(receiver, offset);
86 }
87
88 public long getLong(Object receiver, long offset, boolean condition, Object locationIdentity) {
89 return unsafe.getLong(receiver, offset);
90 }
91
92 public int getInt(Object receiver, long offset, boolean condition, Object locationIdentity) {
93 return unsafe.getInt(receiver, offset);
94 }
95
96 public float getFloat(Object receiver, long offset, boolean condition, Object locationIdentity) {
97 return unsafe.getFloat(receiver, offset);
98 }
99
100 public double getDouble(Object receiver, long offset, boolean condition, Object locationIdentity) {
101 return unsafe.getDouble(receiver, offset);
102 }
103
104 public byte getByte(Object receiver, long offset, boolean condition, Object locationIdentity) {
105 return unsafe.getByte(receiver, offset);
106 }
107
108 public boolean getBoolean(Object receiver, long offset, boolean condition, Object locationIdentity) {
109 return unsafe.getBoolean(receiver, offset);
110 }
111 }
112 }