Repository navigation
Expand file tree
/
Copy pathArrayAccess.java
More file actions
337 lines (307 loc) · 11.4 KB
/
Copy pathArrayAccess.java
File metadata and controls
337 lines (307 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
*
* Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
* that is described in this document. In particular, and without limitation, these intellectual property
* rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
* more additional patents or pending patent applications in the U.S. and in other countries.
*
* U.S. Government Rights - Commercial software. Government users are subject to the Sun
* Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
* supplements.
*
* Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
* registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
* are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
* U.S. and other countries.
*
* UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
* Company, Ltd.
*/
package com.sun.max.vm.object;
import java.lang.reflect.*;
import com.sun.max.annotate.*;
import com.sun.max.unsafe.*;
import com.sun.max.vm.actor.holder.*;
import com.sun.max.vm.compiler.builtin.*;
import com.sun.max.vm.layout.*;
import com.sun.max.vm.reference.*;
import com.sun.max.vm.runtime.*;
/**
* This class implements a facade for the {@link Layout Layout} class. The
* Layout class requires the use of {@link Reference Reference} objects, as opposed
* to regular Java objects, and this class implements a layer around the Layout
* API.
*
* @author Bernd Mathiske
*/
public final class ArrayAccess {
private ArrayAccess() {
}
/**
* Reads the length of the specified array.
*
* @param array the array object
* @return the length of the array
*/
@INLINE
public static int readArrayLength(Object array) {
return Layout.readArrayLength(Reference.fromJava(array));
}
/**
* An inlined method to check an array index against the bounds of the array.
*
* @param array the array object
* @param index the index into the array
*/
@INLINE
public static void checkIndex(Object array, int index) {
// note that we must read the array length first (implicit null check has precedence over bounds check)
if (SpecialBuiltin.aboveEqual(index, readArrayLength(array))) {
Throw.arrayIndexOutOfBoundsException(array, index);
}
}
/**
* Checks that the specified object reference can be assigned to the given object array.
* This implements the same check as the {@code aastore} JVM bytecode.
*
* @param array the array object
* @param value the object reference to write into the specified array
*/
@INLINE
public static void checkSetObject(Object array, Object value) {
if (value != null) {
final ClassActor arrayClassActor = ObjectAccess.readClassActor(array);
if (!arrayClassActor.componentClassActor().isNonNullInstance(value)) {
Throw.arrayStoreException(array, value);
}
}
}
public static Pointer elementPointer(byte[] array, int index) {
return Reference.fromJava(array).toOrigin().plus(Layout.byteArrayLayout().getElementOffsetFromOrigin(index));
}
@INLINE
public static Pointer elementPointer(int[] array, int index) {
return Reference.fromJava(array).toOrigin().plus(Layout.byteArrayLayout().getElementOffsetFromOrigin(index));
}
/**
* Gets a byte from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static byte getByte(Object array, int index) {
return Layout.getByte(Reference.fromJava(array), index);
}
/**
* Sets a byte in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setByte(Object array, int index, byte value) {
Layout.setByte(Reference.fromJava(array), index, value);
}
/**
* Gets a boolean from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static boolean getBoolean(Object array, int index) {
return Layout.getBoolean(Reference.fromJava(array), index);
}
/**
* Sets a boolean in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setBoolean(Object array, int index, boolean value) {
Layout.setBoolean(Reference.fromJava(array), index, value);
}
/**
* Gets a short from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static short getShort(Object array, int index) {
return Layout.getShort(Reference.fromJava(array), index);
}
/**
* Sets a short in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setShort(Object array, int index, short value) {
Layout.setShort(Reference.fromJava(array), index, value);
}
/**
* Gets a char from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static char getChar(Object array, int index) {
return Layout.getChar(Reference.fromJava(array), index);
}
/**
* Sets a char in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setChar(Object array, int index, char value) {
Layout.setChar(Reference.fromJava(array), index, value);
}
/**
* Gets an int from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static int getInt(Object array, int index) {
return Layout.getInt(Reference.fromJava(array), index);
}
/**
* Sets an int in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setInt(Object array, int index, int value) {
Layout.setInt(Reference.fromJava(array), index, value);
}
/**
* Gets a float from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static float getFloat(Object array, int index) {
return Layout.getFloat(Reference.fromJava(array), index);
}
/**
* Sets a float in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setFloat(Object array, int index, float value) {
Layout.setFloat(Reference.fromJava(array), index, value);
}
/**
* Gets a long from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static long getLong(Object array, int index) {
return Layout.getLong(Reference.fromJava(array), index);
}
/**
* Sets a long in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setLong(Object array, int index, long value) {
Layout.setLong(Reference.fromJava(array), index, value);
}
/**
* Gets a double from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static double getDouble(Object array, int index) {
return Layout.getDouble(Reference.fromJava(array), index);
}
/**
* Sets a double in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setDouble(Object array, int index, double value) {
Layout.setDouble(Reference.fromJava(array), index, value);
}
/**
* Gets a word from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static Word getWord(Object array, int index) {
return Layout.getWord(Reference.fromJava(array), index);
}
/**
* Sets a word in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setWord(Object array, int index, Word value) {
Layout.setWord(Reference.fromJava(array), index, value);
}
/**
* Gets a reference from the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @return the value at the specified index in the specified array
*/
@INLINE
public static Object getObject(Object array, int index) {
return Layout.getReference(Reference.fromJava(array), index).toJava();
}
/**
* Sets a reference in the specified array at the specified index.
*
* @param array the array object
* @param index the index into the array
* @param value the value to write into the array at the specified index
*/
@INLINE
public static void setObject(Object array, int index, Object value) {
Layout.setReference(Reference.fromJava(array), index, Reference.fromJava(value));
}
}