Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java @ 21554:b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 23:21:15 +0200 |
parents | 93c50cefb9e8 |
children |
rev | line source |
---|---|
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.compiler.common; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
21541
5e868236654f
moved UnsafeAccess to com.oracle.jvmci.common (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21391
diff
changeset
|
25 import static com.oracle.jvmci.common.UnsafeAccess.*; |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import java.util.*; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21543
diff
changeset
|
29 import sun.misc.*; |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21541
diff
changeset
|
30 |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21543
diff
changeset
|
31 import com.oracle.jvmci.common.*; |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 /** |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 * Describes fields in a class, primarily for access via {@link Unsafe}. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 public class Fields { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
38 /** |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
39 * Offsets used with {@link Unsafe} to access the fields. |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
40 */ |
17233
1278680407e7
moved intrinsifications for Edges back into EdgesSubstitutions
Doug Simon <doug.simon@oracle.com>
parents:
17231
diff
changeset
|
41 protected final long[] offsets; |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
42 |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
43 /** |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
44 * The names of the fields. |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
45 */ |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 private final String[] names; |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
47 |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
48 /** |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
49 * The types of the fields. |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
50 */ |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 private final Class<?>[] types; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
53 private final Class<?>[] declaringClasses; |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
54 |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
55 public static Fields forClass(Class<?> clazz, Class<?> endClazz, boolean includeTransient, FieldsScanner.CalcOffset calcOffset) { |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
56 FieldsScanner scanner = new FieldsScanner(calcOffset == null ? new FieldsScanner.DefaultCalcOffset() : calcOffset); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
57 scanner.scan(clazz, endClazz, includeTransient); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
58 return new Fields(scanner.data); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
59 } |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
60 |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
61 public Fields(ArrayList<? extends FieldsScanner.FieldInfo> fields) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
62 Collections.sort(fields); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
63 this.offsets = new long[fields.size()]; |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 this.names = new String[offsets.length]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 this.types = new Class[offsets.length]; |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
66 this.declaringClasses = new Class[offsets.length]; |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
67 int index = 0; |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
68 for (FieldsScanner.FieldInfo f : fields) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
69 offsets[index] = f.offset; |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
70 names[index] = f.name; |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
71 types[index] = f.type; |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
72 declaringClasses[index] = f.declaringClass; |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
73 index++; |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 /** |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 * Gets the number of fields represented by this object. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 public int getCount() { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 return offsets.length; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
84 public static void translateInto(Fields fields, ArrayList<FieldsScanner.FieldInfo> infos) { |
17247
eed077c367d3
improved performance of NodeClass initialization by improving the way information is derived from super NodeClasses
Doug Simon <doug.simon@oracle.com>
parents:
17244
diff
changeset
|
85 for (int index = 0; index < fields.getCount(); index++) { |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
86 infos.add(new FieldsScanner.FieldInfo(fields.offsets[index], fields.names[index], fields.types[index], fields.declaringClasses[index])); |
17247
eed077c367d3
improved performance of NodeClass initialization by improving the way information is derived from super NodeClasses
Doug Simon <doug.simon@oracle.com>
parents:
17244
diff
changeset
|
87 } |
eed077c367d3
improved performance of NodeClass initialization by improving the way information is derived from super NodeClasses
Doug Simon <doug.simon@oracle.com>
parents:
17244
diff
changeset
|
88 } |
eed077c367d3
improved performance of NodeClass initialization by improving the way information is derived from super NodeClasses
Doug Simon <doug.simon@oracle.com>
parents:
17244
diff
changeset
|
89 |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 /** |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
91 * Function enabling an object field value to be replaced with another value when being copied |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
92 * within {@link Fields#copy(Object, Object, ObjectTransformer)}. |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
93 */ |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
94 @FunctionalInterface |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
95 public interface ObjectTransformer { |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
96 Object apply(int index, Object from); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
97 } |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
98 |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
99 /** |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
100 * Copies fields from {@code from} to {@code to}, both of which must be of the same type. |
17329
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
101 * |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
102 * @param from the object from which the fields should be copied |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
103 * @param to the object to which the fields should be copied |
17329
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
104 */ |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
105 public void copy(Object from, Object to) { |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
106 copy(from, to, null); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
107 } |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
108 |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
109 /** |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
110 * Copies fields from {@code from} to {@code to}, both of which must be of the same type. |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
111 * |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
112 * @param from the object from which the fields should be copied |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
113 * @param to the object to which the fields should be copied |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
114 * @param trans function to applied to object field values as they are copied. If {@code null}, |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
115 * the value is copied unchanged. |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
116 */ |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
117 public void copy(Object from, Object to, ObjectTransformer trans) { |
17329
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
118 assert from.getClass() == to.getClass(); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
119 for (int index = 0; index < offsets.length; index++) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
120 long offset = offsets[index]; |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
121 Class<?> type = types[index]; |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
122 if (type.isPrimitive()) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
123 if (type == Integer.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
124 unsafe.putInt(to, offset, unsafe.getInt(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
125 } else if (type == Long.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
126 unsafe.putLong(to, offset, unsafe.getLong(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
127 } else if (type == Boolean.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
128 unsafe.putBoolean(to, offset, unsafe.getBoolean(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
129 } else if (type == Float.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
130 unsafe.putFloat(to, offset, unsafe.getFloat(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
131 } else if (type == Double.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
132 unsafe.putDouble(to, offset, unsafe.getDouble(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
133 } else if (type == Short.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
134 unsafe.putShort(to, offset, unsafe.getShort(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
135 } else if (type == Character.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
136 unsafe.putChar(to, offset, unsafe.getChar(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
137 } else if (type == Byte.TYPE) { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
138 unsafe.putByte(to, offset, unsafe.getByte(from, offset)); |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
139 } else { |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
140 assert false : "unhandled property type: " + type; |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
141 } |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
142 } else { |
18261
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
143 Object obj = unsafe.getObject(from, offset); |
d66c79acfeac
refactored Fields class to make it usable for implementing custom serialization
Doug Simon <doug.simon@oracle.com>
parents:
17329
diff
changeset
|
144 unsafe.putObject(to, offset, trans == null ? obj : trans.apply(index, obj)); |
17329
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
145 } |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
146 } |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
147 } |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
148 |
1e7e354e407f
use Unsafe.allocateInstance in Node.clone(Graph into, boolean clearInputsAndSuccessors) to avoid initializing fields twice
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
149 /** |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
150 * Gets the value of a field for a given object. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
151 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 * @param object the object whose field is to be read |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
153 * @param index the index of the field (between 0 and {@link #getCount()}) |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
154 * @return the value of the specified field which will be boxed if the field type is primitive |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
155 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
156 public Object get(Object object, int index) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
157 long offset = offsets[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 Class<?> type = types[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 Object value = null; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 if (type.isPrimitive()) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 if (type == Integer.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 value = unsafe.getInt(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 } else if (type == Long.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
164 value = unsafe.getLong(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
165 } else if (type == Boolean.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
166 value = unsafe.getBoolean(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 } else if (type == Float.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 value = unsafe.getFloat(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
169 } else if (type == Double.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
170 value = unsafe.getDouble(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 } else if (type == Short.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
172 value = unsafe.getShort(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
173 } else if (type == Character.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 value = unsafe.getChar(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 } else if (type == Byte.TYPE) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 value = unsafe.getByte(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 } else { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 assert false : "unhandled property type: " + type; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 } else { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
181 value = unsafe.getObject(object, offset); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 return value; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
185 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
186 /** |
20827
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
187 * Gets the value of a field for a given object. |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
188 * |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
189 * @param object the object whose field is to be read |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
190 * @param index the index of the field (between 0 and {@link #getCount()}) |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
191 * @return the value of the specified field which will be boxed if the field type is primitive |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
192 */ |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
193 public long getRawPrimitive(Object object, int index) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
194 long offset = offsets[index]; |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
195 Class<?> type = types[index]; |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
196 |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
197 if (type == Integer.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
198 return unsafe.getInt(object, offset); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
199 } else if (type == Long.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
200 return unsafe.getLong(object, offset); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
201 } else if (type == Boolean.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
202 return unsafe.getBoolean(object, offset) ? 1 : 0; |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
203 } else if (type == Float.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
204 return Float.floatToRawIntBits(unsafe.getFloat(object, offset)); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
205 } else if (type == Double.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
206 return Double.doubleToRawLongBits(unsafe.getDouble(object, offset)); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
207 } else if (type == Short.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
208 return unsafe.getShort(object, offset); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
209 } else if (type == Character.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
210 return unsafe.getChar(object, offset); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
211 } else if (type == Byte.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
212 return unsafe.getByte(object, offset); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
213 } else { |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21541
diff
changeset
|
214 throw JVMCIError.shouldNotReachHere(); |
20827
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
215 } |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
216 } |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
217 |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
218 /** |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
219 * Determines if a field in the domain of this object is the same as the field denoted by the |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
220 * same index in another {@link Fields} object. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
221 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
222 public boolean isSame(Fields other, int index) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
223 return other.offsets[index] == offsets[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
224 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
225 |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
226 public long[] getOffsets() { |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
227 return offsets; |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
228 } |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
229 |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
230 /** |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
231 * Gets the name of a field. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
232 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
233 * @param index index of a field |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
234 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
235 public String getName(int index) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
236 return names[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
237 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
238 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
239 /** |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
240 * Gets the type of a field. |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
241 * |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
242 * @param index index of a field |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
243 */ |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
244 public Class<?> getType(int index) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
245 return types[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
246 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
247 |
21391
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
248 public Class<?> getDeclaringClass(int index) { |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
249 return declaringClasses[index]; |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
250 } |
8cc395785d0a
Expand functionality of FieldIntrospection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20827
diff
changeset
|
251 |
17231
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
252 /** |
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
253 * Checks that a given field is assignable from a given value. |
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
254 * |
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
255 * @param index the index of the field to check |
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
256 * @param value a value that will be assigned to the field |
58f1d1335ef4
force inline Fields.getObject(Object, int, Class) so that a constant value bound to its last parameter is connected with the DeferredPiNode used in Fields.getObject(Object, long, Class)
Doug Simon <doug.simon@oracle.com>
parents:
17226
diff
changeset
|
257 */ |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
258 private boolean checkAssignableFrom(Object object, int index, Object value) { |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
259 assert value == null || getType(index).isAssignableFrom(value.getClass()) : String.format("Field %s.%s of type %s is not assignable from %s", object.getClass().getSimpleName(), |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
260 getName(index), getType(index).getSimpleName(), value.getClass().getSimpleName()); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
261 return true; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
262 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
263 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
264 public void set(Object object, int index, Object value) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
265 long offset = offsets[index]; |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
266 Class<?> type = types[index]; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
267 if (type.isPrimitive()) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
268 if (type == Integer.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
269 unsafe.putInt(object, offset, (Integer) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
270 } else if (type == Long.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
271 unsafe.putLong(object, offset, (Long) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
272 } else if (type == Boolean.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
273 unsafe.putBoolean(object, offset, (Boolean) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
274 } else if (type == Float.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
275 unsafe.putFloat(object, offset, (Float) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
276 } else if (type == Double.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
277 unsafe.putDouble(object, offset, (Double) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
278 } else if (type == Short.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
279 unsafe.putShort(object, offset, (Short) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
280 } else if (type == Character.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
281 unsafe.putChar(object, offset, (Character) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
282 } else if (type == Byte.TYPE) { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
283 unsafe.putByte(object, offset, (Byte) value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
284 } else { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
285 assert false : "unhandled property type: " + type; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
286 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
287 } else { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
288 assert checkAssignableFrom(object, index, value); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
289 unsafe.putObject(object, offset, value); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
290 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
291 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
292 |
20827
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
293 public void setRawPrimitive(Object object, int index, long value) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
294 long offset = offsets[index]; |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
295 Class<?> type = types[index]; |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
296 if (type == Integer.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
297 unsafe.putInt(object, offset, (int) value); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
298 } else if (type == Long.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
299 unsafe.putLong(object, offset, value); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
300 } else if (type == Boolean.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
301 unsafe.putBoolean(object, offset, value != 0); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
302 } else if (type == Float.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
303 unsafe.putFloat(object, offset, Float.intBitsToFloat((int) value)); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
304 } else if (type == Double.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
305 unsafe.putDouble(object, offset, Double.longBitsToDouble(value)); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
306 } else if (type == Short.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
307 unsafe.putShort(object, offset, (short) value); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
308 } else if (type == Character.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
309 unsafe.putChar(object, offset, (char) value); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
310 } else if (type == Byte.TYPE) { |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
311 unsafe.putByte(object, offset, (byte) value); |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
312 } else { |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21541
diff
changeset
|
313 throw JVMCIError.shouldNotReachHere(); |
20827
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
314 } |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
315 } |
5bf195ce816a
New partial evaluator that works on encoded graphs (instead of on bytecodes)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18261
diff
changeset
|
316 |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
317 @Override |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
318 public String toString() { |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
319 StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('['); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
320 appendFields(sb); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
321 return sb.append(']').toString(); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
322 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
323 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
324 public void appendFields(StringBuilder sb) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
325 for (int i = 0; i < offsets.length; i++) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
326 sb.append(i == 0 ? "" : ", ").append(getName(i)).append('@').append(offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
327 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
328 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
329 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
330 public boolean getBoolean(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
331 assert types[i] == boolean.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
332 return unsafe.getBoolean(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
333 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
334 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
335 public byte getByte(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
336 assert types[i] == byte.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
337 return unsafe.getByte(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
338 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
339 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
340 public short getShort(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
341 assert types[i] == short.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
342 return unsafe.getShort(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
343 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
344 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
345 public char getChar(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
346 assert types[i] == char.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
347 return unsafe.getChar(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
348 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
349 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
350 public int getInt(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
351 assert types[i] == int.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
352 return unsafe.getInt(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
353 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
354 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
355 public long getLong(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
356 assert types[i] == long.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
357 return unsafe.getLong(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
358 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
359 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
360 public float getFloat(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
361 assert types[i] == float.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
362 return unsafe.getFloat(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
363 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
364 |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
365 public double getDouble(Object n, int i) { |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
366 assert types[i] == double.class; |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
367 return unsafe.getDouble(n, offsets[i]); |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
368 } |
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
369 |
17233
1278680407e7
moved intrinsifications for Edges back into EdgesSubstitutions
Doug Simon <doug.simon@oracle.com>
parents:
17231
diff
changeset
|
370 public Object getObject(Object object, int i) { |
1278680407e7
moved intrinsifications for Edges back into EdgesSubstitutions
Doug Simon <doug.simon@oracle.com>
parents:
17231
diff
changeset
|
371 assert !types[i].isPrimitive(); |
1278680407e7
moved intrinsifications for Edges back into EdgesSubstitutions
Doug Simon <doug.simon@oracle.com>
parents:
17231
diff
changeset
|
372 return unsafe.getObject(object, offsets[i]); |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
373 } |
17244
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
374 |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
375 public void putObject(Object object, int i, Object value) { |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
376 assert checkAssignableFrom(object, i, value); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
377 unsafe.putObject(object, offsets[i], value); |
aef31f60e970
converted all FieldIntrospection subclass to use Fields
Doug Simon <doug.simon@oracle.com>
parents:
17233
diff
changeset
|
378 } |
17226
a552dd335bde
generalized support for unsafe access to a subset of the fields of an object
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
379 } |