Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/BasicAllocator.java @ 21951:9c8c0937da41
Moving all sources into truffle subdirectory
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 10:58:08 +0200 |
parents | graal/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/BasicAllocator.java@2c3666f44855 |
children | dc83cc1f94f2 |
comparison
equal
deleted
inserted
replaced
21950:2a5011c7e641 | 21951:9c8c0937da41 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2014, 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.object.basic; | |
24 | |
25 import static com.oracle.truffle.object.basic.BasicLocations.*; | |
26 | |
27 import com.oracle.truffle.api.object.*; | |
28 import com.oracle.truffle.object.*; | |
29 import com.oracle.truffle.object.LocationImpl.InternalLongLocation; | |
30 import com.oracle.truffle.object.Locations.ConstantLocation; | |
31 import com.oracle.truffle.object.Locations.DeclaredDualLocation; | |
32 import com.oracle.truffle.object.Locations.DualLocation; | |
33 import com.oracle.truffle.object.Locations.ValueLocation; | |
34 import com.oracle.truffle.object.basic.BasicLocations.BooleanLocationDecorator; | |
35 import com.oracle.truffle.object.basic.BasicLocations.DoubleLocationDecorator; | |
36 import com.oracle.truffle.object.basic.BasicLocations.IntLocationDecorator; | |
37 import com.oracle.truffle.object.basic.BasicLocations.LongArrayLocation; | |
38 import com.oracle.truffle.object.basic.BasicLocations.LongFieldLocation; | |
39 import com.oracle.truffle.object.basic.BasicLocations.ObjectArrayLocation; | |
40 | |
41 public abstract class BasicAllocator extends ShapeImpl.BaseAllocator { | |
42 | |
43 public BasicAllocator(LayoutImpl layout) { | |
44 super(layout); | |
45 advance(((BasicLayout) layout).getPrimitiveArrayLocation()); | |
46 } | |
47 | |
48 public BasicAllocator(ShapeImpl shape) { | |
49 super(shape); | |
50 } | |
51 | |
52 private BasicLayout getLayout() { | |
53 return (BasicLayout) layout; | |
54 } | |
55 | |
56 @Override | |
57 protected Location moveLocation(Location oldLocation) { | |
58 if (oldLocation instanceof DeclaredDualLocation) { | |
59 return advance(newDeclaredDualLocation(((DeclaredDualLocation) oldLocation).get(null, false))); | |
60 } else if (oldLocation instanceof DualLocation) { | |
61 return advance(newDualLocation(((DualLocation) oldLocation).getType())); | |
62 } else if (oldLocation instanceof LongLocation) { | |
63 return newLongLocation(oldLocation.isFinal()); | |
64 } else if (oldLocation instanceof IntLocation) { | |
65 return newIntLocation(oldLocation.isFinal()); | |
66 } else if (oldLocation instanceof DoubleLocation) { | |
67 return newDoubleLocation(oldLocation.isFinal()); | |
68 } else if (oldLocation instanceof BooleanLocation) { | |
69 return newBooleanLocation(oldLocation.isFinal()); | |
70 } else if (oldLocation instanceof ObjectLocation) { | |
71 return newObjectLocation(oldLocation.isFinal(), ((ObjectLocation) oldLocation).isNonNull()); | |
72 } else { | |
73 assert oldLocation instanceof ValueLocation; | |
74 return advance(oldLocation); | |
75 } | |
76 } | |
77 | |
78 @Override | |
79 public Location newObjectLocation(boolean useFinal, boolean nonNull) { | |
80 if (ObjectStorageOptions.InObjectFields) { | |
81 int insertPos = objectFieldSize; | |
82 while (insertPos + OBJECT_SIZE <= getLayout().getObjectFieldCount()) { | |
83 return advance((Location) getLayout().getObjectFieldLocation(insertPos)); | |
84 } | |
85 } | |
86 return newObjectArrayLocation(useFinal, nonNull); | |
87 } | |
88 | |
89 @SuppressWarnings("unused") | |
90 private Location newObjectArrayLocation(boolean useFinal, boolean nonNull) { | |
91 return advance(new ObjectArrayLocation(objectArraySize, getLayout().getObjectArrayLocation())); | |
92 } | |
93 | |
94 @Override | |
95 public Location newTypedObjectLocation(boolean useFinal, Class<?> type, boolean nonNull) { | |
96 return newObjectLocation(useFinal, nonNull); | |
97 } | |
98 | |
99 @Override | |
100 public Location newIntLocation(boolean useFinal) { | |
101 if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.IntegerLocations) { | |
102 if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + LONG_SIZE <= getLayout().getPrimitiveFieldCount()) { | |
103 return advance(new IntLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize))); | |
104 } else if (getLayout().hasPrimitiveExtensionArray() && isPrimitiveExtensionArrayAvailable()) { | |
105 return advance(new IntLocationDecorator(new LongArrayLocation(primitiveArraySize, getLayout().getPrimitiveArrayLocation()))); | |
106 } | |
107 } | |
108 return newObjectLocation(useFinal, true); | |
109 } | |
110 | |
111 @Override | |
112 public Location newDoubleLocation(boolean useFinal) { | |
113 if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.DoubleLocations) { | |
114 if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + LONG_SIZE <= getLayout().getPrimitiveFieldCount()) { | |
115 return advance(new DoubleLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize), getLayout().isAllowedIntToDouble())); | |
116 } else if (getLayout().hasPrimitiveExtensionArray() && isPrimitiveExtensionArrayAvailable()) { | |
117 return advance(new DoubleLocationDecorator(new LongArrayLocation(primitiveArraySize, getLayout().getPrimitiveArrayLocation()), getLayout().isAllowedIntToDouble())); | |
118 } | |
119 } | |
120 return newObjectLocation(useFinal, true); | |
121 } | |
122 | |
123 @Override | |
124 public Location newLongLocation(boolean useFinal) { | |
125 if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.LongLocations) { | |
126 if (ObjectStorageOptions.InObjectFields && primitiveFieldSize + LONG_SIZE <= getLayout().getPrimitiveFieldCount()) { | |
127 return advance((Location) LongFieldLocation.create(getLayout().getPrimitiveFieldLocation(primitiveFieldSize), getLayout().isAllowedIntToLong())); | |
128 } else if (getLayout().hasPrimitiveExtensionArray() && isPrimitiveExtensionArrayAvailable()) { | |
129 return advance(new LongArrayLocation(primitiveArraySize, getLayout().getPrimitiveArrayLocation(), getLayout().isAllowedIntToLong())); | |
130 } | |
131 } | |
132 return newObjectLocation(useFinal, true); | |
133 } | |
134 | |
135 @Override | |
136 public Location newBooleanLocation(boolean useFinal) { | |
137 if (ObjectStorageOptions.PrimitiveLocations && ObjectStorageOptions.BooleanLocations) { | |
138 if (primitiveFieldSize + LONG_SIZE <= getLayout().getPrimitiveFieldCount()) { | |
139 return advance(new BooleanLocationDecorator(getLayout().getPrimitiveFieldLocation(primitiveFieldSize))); | |
140 } | |
141 } | |
142 return newObjectLocation(useFinal, true); | |
143 } | |
144 | |
145 private boolean isPrimitiveExtensionArrayAvailable() { | |
146 return hasPrimitiveArray; | |
147 } | |
148 | |
149 @Override | |
150 protected Location locationForValueUpcast(Object value, Location oldLocation) { | |
151 assert !(value instanceof Class); | |
152 if (oldLocation instanceof DualLocation) { | |
153 DualLocation dualLocation = (DualLocation) oldLocation; | |
154 if (dualLocation.getType() == null) { | |
155 if (value instanceof Integer) { | |
156 return dualLocation.changeType(int.class); | |
157 } else if (value instanceof Double) { | |
158 return dualLocation.changeType(double.class); | |
159 } else if (value instanceof Long) { | |
160 return dualLocation.changeType(long.class); | |
161 } else if (value instanceof Boolean) { | |
162 return dualLocation.changeType(boolean.class); | |
163 } else { | |
164 return dualLocation.changeType(Object.class); | |
165 } | |
166 } else if (dualLocation.getType().isPrimitive()) { | |
167 return dualLocation.changeType(Object.class); | |
168 } else { | |
169 throw new UnsupportedOperationException(); | |
170 } | |
171 } else if (oldLocation instanceof ConstantLocation) { | |
172 return constantLocation(value); | |
173 } else { | |
174 throw new UnsupportedOperationException(); | |
175 } | |
176 } | |
177 | |
178 @Override | |
179 protected DeclaredDualLocation newDeclaredDualLocation(Object value) { | |
180 return new DeclaredDualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), value, layout); | |
181 } | |
182 } |