annotate truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/LayoutImpl.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/src/com/oracle/truffle/object/LayoutImpl.java@2c3666f44855
children dc83cc1f94f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
4 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
8 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
13 * accompanied this code).
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
14 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
18 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
21 * questions.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
22 */
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
23 package com.oracle.truffle.object;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
24
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
25 import java.util.*;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
26
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
27 import com.oracle.truffle.api.object.*;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
28 import com.oracle.truffle.api.object.Shape.Allocator;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
29 import com.oracle.truffle.object.LocationImpl.EffectivelyFinalLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
30 import com.oracle.truffle.object.LocationImpl.TypedObjectLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
31 import com.oracle.truffle.object.Locations.ConstantLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
32 import com.oracle.truffle.object.Locations.DeclaredLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
33 import com.oracle.truffle.object.Locations.DualLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
34 import com.oracle.truffle.object.Locations.ValueLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
35 import com.oracle.truffle.object.ShapeImpl.BaseAllocator;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37 public abstract class LayoutImpl extends Layout {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
38 private static final int INT_TO_DOUBLE_FLAG = 1;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
39 private static final int INT_TO_LONG_FLAG = 2;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 private final LayoutStrategy strategy;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
42 private final Class<? extends DynamicObject> clazz;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43 private final int allowedImplicitCasts;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45 protected LayoutImpl(EnumSet<ImplicitCast> allowedImplicitCasts, Class<? extends DynamicObjectImpl> clazz, LayoutStrategy strategy) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
46 this.strategy = strategy;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
47 this.clazz = clazz;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
49 this.allowedImplicitCasts = (allowedImplicitCasts.contains(ImplicitCast.IntToDouble) ? INT_TO_DOUBLE_FLAG : 0) | (allowedImplicitCasts.contains(ImplicitCast.IntToLong) ? INT_TO_LONG_FLAG : 0);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
50 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
51
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
52 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53 public abstract DynamicObject newInstance(Shape shape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
54
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
55 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
56 public Class<? extends DynamicObject> getType() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
57 return clazz;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
58 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
61 public final Shape createShape(ObjectType operations, Object sharedData) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
62 return createShape(operations, sharedData, 0);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
63 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
64
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
65 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
66 public final Shape createShape(ObjectType operations) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67 return createShape(operations, null);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
68 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
69
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
70 public boolean isAllowedIntToDouble() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71 return (allowedImplicitCasts & INT_TO_DOUBLE_FLAG) != 0;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
72 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
73
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
74 public boolean isAllowedIntToLong() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
75 return (allowedImplicitCasts & INT_TO_LONG_FLAG) != 0;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
76 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
77
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
78 protected abstract boolean hasObjectExtensionArray();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80 protected abstract boolean hasPrimitiveExtensionArray();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
82 protected abstract int getObjectFieldCount();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
83
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
84 protected abstract int getPrimitiveFieldCount();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
85
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
86 protected abstract Location getObjectArrayLocation();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
87
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
88 protected abstract Location getPrimitiveArrayLocation();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90 protected abstract int objectFieldIndex(Location location);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
91
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
92 protected boolean isLocationAssignableFrom(Location destination, Location source) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 LayoutImpl layout = this;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
94 if (destination.isFinal()) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
95 // allowed Final<X>Location => Final<X>Location
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96 // allowed FinalIntLocation => Final{Int,Double}Location
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 // allowed: Final{Int,Double,TypedObject}Location => FinalObjectLocation
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98 if (!source.isFinal()) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 return false;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
103 if (destination instanceof IntLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 return (source instanceof IntLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
105 } else if (destination instanceof DoubleLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
106 return (source instanceof DoubleLocation || (layout.isAllowedIntToDouble() && source instanceof IntLocation));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 } else if (destination instanceof LongLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108 return (source instanceof LongLocation || (layout.isAllowedIntToLong() && source instanceof IntLocation));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 } else if (destination instanceof BooleanLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110 return (source instanceof BooleanLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
111 } else if (destination instanceof TypedObjectLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
112 return source instanceof TypedObjectLocation && ((TypedObjectLocation<?>) destination).getType().isAssignableFrom(((TypedObjectLocation<?>) source).getType());
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
113 } else if (destination instanceof ValueLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
114 return false;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
115 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
116 assert destination instanceof ObjectLocation || destination instanceof DualLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
117 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
118 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
119 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
120
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
121 protected Location existingLocationForValue(Object value, Location oldLocation, Shape oldShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
122 assert oldShape.getLayout() == this;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
123 Location newLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
124 if (oldLocation instanceof IntLocation && value instanceof Integer) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
125 newLocation = oldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
126 } else if (oldLocation instanceof DoubleLocation && (value instanceof Double || this.isAllowedIntToDouble() && value instanceof Integer)) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
127 newLocation = oldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
128 } else if (oldLocation instanceof LongLocation && (value instanceof Long || this.isAllowedIntToLong() && value instanceof Long)) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
129 newLocation = oldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
130 } else if (oldLocation instanceof DeclaredLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
131 return oldShape.allocator().locationForValue(value, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
132 } else if (oldLocation instanceof ConstantLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
133 return LocationImpl.valueEquals(oldLocation.get(null, false), value) ? oldLocation : new Locations.ConstantLocation(value);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
134 } else if (oldLocation instanceof TypedObjectLocation && !((TypedObjectLocation<?>) oldLocation).getType().isAssignableFrom(value.getClass())) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
135 newLocation = (((TypedObjectLocation<?>) oldLocation).toUntypedLocation());
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
136 } else if (oldLocation instanceof DualLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
137 if (oldLocation.canStore(value)) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
138 newLocation = oldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
139 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
140 newLocation = ((BaseAllocator) oldShape.allocator()).locationForValueUpcast(value, oldLocation);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
141 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
142 } else if (oldLocation instanceof ObjectLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
143 newLocation = oldLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
144 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
145 return oldShape.allocator().locationForValue(value, EnumSet.of(LocationModifier.NonNull));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
146 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
147 if (newLocation instanceof EffectivelyFinalLocation) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
148 newLocation = ((EffectivelyFinalLocation<?>) newLocation).toNonFinalLocation();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
149 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
150 return newLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
151 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
152
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
153 /**
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
154 * Is this property an upcast of the other property?
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
155 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
156 * @param other the property being compared to
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
157 * @return true if this is a upcast of the other property, false otherwise
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
158 */
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
159 public boolean isPropertyUpcastOf(Property thiz, Property other) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
160 if (thiz.getLocation() != null && other.getLocation() != null && other.getKey().equals(thiz.getKey()) && other.getFlags() == thiz.getFlags()) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
161 if (isLocationAssignableFrom(thiz.getLocation(), other.getLocation())) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
162 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
163 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
164 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
165 return false;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
166 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
167
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
168 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
169 public abstract Allocator createAllocator();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
170
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
171 public LayoutStrategy getStrategy() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
172 return strategy;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
173 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
174 }