Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java @ 18408:2c3666f44855
Truffle: initial commit of object API implementation
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 18 Nov 2014 23:19:43 +0100 |
parents | |
children | b3b241bbbbdb |
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.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.nodes.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.object.*; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 import com.oracle.truffle.object.LocationImpl.InternalLongLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 import com.oracle.truffle.object.Locations.ConstantLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
34 import com.oracle.truffle.object.Locations.DeclaredDualLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 import com.oracle.truffle.object.Locations.DeclaredLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 import com.oracle.truffle.object.Locations.DualLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
37 import com.oracle.truffle.object.Locations.ValueLocation; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
38 import com.oracle.truffle.object.Transition.AddTransition; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
39 import com.oracle.truffle.object.Transition.OperationsTransition; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
40 import com.oracle.truffle.object.Transition.PropertyTransition; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 import com.oracle.truffle.object.Transition.RemoveTransition; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 * Shape objects create a mapping of Property objects to indexes. The mapping of those indexes to an |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 * actual store is not part of Shape's role, but JSObject's. Shapes are immutable; adding or |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 * deleting a property yields a new Shape which links to the old one. This allows inline caching to |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 * simply check the identity of an object's Shape to determine if the cache is valid. There is one |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 * exception to this immutability, the transition map, but that is used simply to assure that an |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
49 * identical series of property additions and deletions will yield the same Shape object. |
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 * @see DynamicObject |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
52 * @see Property |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 * @see Locations |
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 public abstract class ShapeImpl extends Shape { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
56 private final int id; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
57 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
58 protected final LayoutImpl layout; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
59 protected final ObjectType objectType; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 protected final ShapeImpl parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
61 protected final PropertyMap propertyMap; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
62 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
63 private final Object extraData; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
64 private final Object sharedData; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
65 private final ShapeImpl root; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
66 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
67 protected final int objectArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
68 protected final int objectArrayCapacity; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
69 protected final int objectFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 protected final int primitiveFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
71 protected final int primitiveArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 protected final int primitiveArrayCapacity; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 protected final boolean hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 protected final int depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 protected final int propertyCount; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 protected Property[] propertyArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 protected final Assumption validAssumption; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 protected final Assumption leafAssumption; |
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 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
83 * Shape transition map; lazily initialized. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
84 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 * @see #getTransitionMapForRead() |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
86 * @see #getTransitionMapForWrite() |
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 private HashMap<Transition, ShapeImpl> transitionMap; |
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 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
91 * Private constructor. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
92 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
93 * @see #ShapeImpl(Layout, ShapeImpl, ObjectType, Object, PropertyMap, BaseAllocator, int) |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
94 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 private ShapeImpl(Layout layout, ShapeImpl parent, ObjectType operations, Object sharedData, PropertyMap propertyMap, int objectArraySize, int objectFieldSize, int primitiveFieldSize, |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 int primitiveArraySize, boolean hasPrimitiveArray, int id) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
97 this.layout = (LayoutImpl) layout; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 this.objectType = Objects.requireNonNull(operations); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 this.propertyMap = Objects.requireNonNull(propertyMap); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
100 this.root = parent != null ? parent.getRoot() : this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
101 this.parent = parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
102 this.objectArraySize = objectArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
103 this.objectArrayCapacity = capacityFromSize(objectArraySize); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
104 this.objectFieldSize = objectFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
105 this.primitiveFieldSize = primitiveFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
106 this.primitiveArraySize = primitiveArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
107 this.primitiveArrayCapacity = capacityFromSize(primitiveArraySize); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
108 this.hasPrimitiveArray = hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
109 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
110 if (parent != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
111 this.propertyCount = makePropertyCount(parent, propertyMap); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
112 this.propertyArray = makePropertiesList(parent, propertyMap); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
113 this.depth = parent.depth + 1; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
114 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
115 this.propertyCount = 0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
116 this.propertyArray = null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
117 this.depth = 0; |
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 this.validAssumption = createValidAssumption(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
121 this.leafAssumption = createLeafAssumption(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
122 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
123 this.id = id; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
124 shapeCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
125 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
126 this.sharedData = sharedData; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
127 this.extraData = operations.createShapeData(this); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
128 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
129 debugRegisterShape(this); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
130 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
131 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
132 protected ShapeImpl(Layout layout, ShapeImpl parent, ObjectType operations, Object sharedData, PropertyMap propertyMap, Allocator allocator, int id) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
133 this(layout, parent, operations, sharedData, propertyMap, ((BaseAllocator) allocator).objectArraySize, ((BaseAllocator) allocator).objectFieldSize, |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
134 ((BaseAllocator) allocator).primitiveFieldSize, ((BaseAllocator) allocator).primitiveArraySize, ((BaseAllocator) allocator).hasPrimitiveArray, id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
135 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
136 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
137 @SuppressWarnings("hiding") |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
138 protected abstract ShapeImpl createShape(Layout layout, Object sharedData, ShapeImpl parent, ObjectType operations, PropertyMap propertyMap, Allocator allocator, int id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
139 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
140 protected ShapeImpl(Layout layout, ObjectType operations, Object sharedData, int id) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
141 this(layout, null, operations, sharedData, PropertyMap.empty(), layout.createAllocator(), id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
142 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
143 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
144 private static int makePropertyCount(ShapeImpl parent, PropertyMap propertyMap) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
145 return parent.propertyCount + ((propertyMap.size() > parent.propertyMap.size() && !propertyMap.getLastProperty().isHidden() && !propertyMap.getLastProperty().isShadow()) ? 1 : 0); |
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 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
148 private static Property[] makePropertiesList(ShapeImpl parent, PropertyMap propertyMap) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
149 Property[] properties = parent.propertyArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
150 if (properties != null && propertyMap.size() != parent.propertyMap.size()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
151 Property lastProperty = propertyMap.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
152 if (lastProperty != null && !lastProperty.isHidden()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
153 propertyListAllocCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
154 if (!lastProperty.isShadow()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
155 properties = Arrays.copyOf(properties, properties.length + 1); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
156 properties[properties.length - 1] = lastProperty; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
157 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
158 properties = Arrays.copyOf(properties, properties.length); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
159 for (int i = 0; i < properties.length; i++) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
160 if (properties[i].isSame(lastProperty)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
161 properties[i] = lastProperty; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
162 } |
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 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
166 propertyListShareCount.inc(); |
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 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
169 return properties; |
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 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
172 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
173 public final Property getLastProperty() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
174 return propertyMap.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
175 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
176 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
177 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
178 public final int getId() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
179 return this.id; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
180 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
181 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
182 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
183 * Calculate array size for the given number of elements. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
184 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
185 private static int capacityFromSize(int size) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
186 if (size == 0) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
187 return 0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
188 } else if (size < 4) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
189 return 4; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
190 } else if (size < 32) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
191 return ((size + 7) / 8) * 8; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
192 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
193 return ((size + 15) / 16) * 16; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
194 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
195 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
196 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
197 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
198 public final int getObjectArraySize() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
199 return objectArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
200 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
201 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
202 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
203 public final int getObjectFieldSize() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
204 return objectFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
205 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
206 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
207 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
208 public final int getPrimitiveFieldSize() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
209 return primitiveFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
210 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
211 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
212 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
213 public final int getObjectArrayCapacity() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
214 return objectArrayCapacity; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
215 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
216 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
217 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
218 public final int getPrimitiveArrayCapacity() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
219 return primitiveArrayCapacity; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
220 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
221 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
222 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
223 public final int getPrimitiveArraySize() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
224 return primitiveArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
225 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
226 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
227 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
228 public final boolean hasPrimitiveArray() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
229 return hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
230 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
231 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
232 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
233 * Get the (parent) shape that holds the given property. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
234 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
235 public final ShapeImpl getShapeFromProperty(Object propertyName) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
236 ShapeImpl current = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
237 while (current != getRoot()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
238 if (current.getLastProperty().getKey().equals(propertyName)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
239 return current; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
240 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
241 current = current.getParent(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
242 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
243 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
244 return null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
245 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
246 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
247 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
248 * Get the (parent) shape that holds the given property. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
249 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
250 public final ShapeImpl getShapeFromProperty(Property prop) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
251 ShapeImpl current = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
252 while (current != getRoot()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
253 if (current.getLastProperty().equals(prop)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
254 return current; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
255 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
256 current = current.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
257 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
258 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
259 return null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
260 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
261 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
262 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
263 * Get a property entry by string name. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
264 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
265 * @param key the name to look up |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
266 * @return a Property object, or null if not found |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
267 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
268 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
269 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
270 public final Property getProperty(Object key) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
271 // return this.propertyMap.get(propertyName); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
272 PropertyMap current = this.propertyMap; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
273 while (current.getLastProperty() != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
274 if (current.getLastProperty().getKey().equals(key)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
275 return current.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
276 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
277 current = current.getParentMap(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
278 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
279 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
280 return null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
281 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
282 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
283 protected final void addTransition(Transition transition, ShapeImpl next) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
284 assert next.getParent() == this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
285 addTransitionInternal(transition, next); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
286 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
287 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
288 public final void addNonlinearTransition(Transition transition, ShapeImpl next) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
289 assert next.getParent() != this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
290 addTransitionInternal(transition, next); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
291 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
292 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
293 private void addTransitionInternal(Transition transition, ShapeImpl next) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
294 getTransitionMapForWrite().put(transition, next); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
295 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
296 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
297 public final Map<Transition, ShapeImpl> getTransitionMapForRead() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
298 return transitionMap != null ? transitionMap : Collections.<Transition, ShapeImpl> emptyMap(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
299 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
300 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
301 private Map<Transition, ShapeImpl> getTransitionMapForWrite() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
302 if (transitionMap != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
303 return transitionMap; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
304 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
305 invalidateLeafAssumption(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
306 return transitionMap = new HashMap<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
307 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
308 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
309 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
310 public final PropertyMap getPropertyMap() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
311 return propertyMap; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
312 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
313 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
314 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
315 * Add a new property in the map, yielding a new or cached Shape object. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
316 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
317 * @param property the property to add |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
318 * @return the new Shape |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
319 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
320 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
321 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
322 public ShapeImpl addProperty(Property property) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
323 assert isValid(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
324 ShapeImpl nextShape = addPropertyInternal(property); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
325 objectType.onPropertyAdded(property, this, nextShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
326 return nextShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
327 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
328 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
329 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
330 * Add a new property in the map, yielding a new or cached Shape object. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
331 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
332 * In contrast to {@link ShapeImpl#addProperty(Property)}, this method does not care about |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
333 * obsolete shapes. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
334 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
335 * @see #addProperty(Property) |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
336 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
337 private ShapeImpl addPropertyInternal(Property prop) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
338 CompilerAsserts.neverPartOfCompilation(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
339 assert prop.isShadow() || !(this.hasProperty(prop.getKey())) : "duplicate property"; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
340 assert !getPropertyListInternal(false).contains(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
341 // invalidatePropertyAssumption(prop.getName()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
342 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
343 Transition.AddTransition key = new Transition.AddTransition(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
344 Map<Transition, ShapeImpl> transitionMapForRead = this.getTransitionMapForRead(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
345 ShapeImpl cachedShape = transitionMapForRead.get(key); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
346 if (cachedShape != null) { // Shape already exists? |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
347 shapeCacheHitCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
348 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
349 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
350 shapeCacheMissCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
351 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
352 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, prop.getLocation()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
353 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
354 ShapeImpl newShape = makeShapeWithAddedProperty(oldShape, key); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
355 oldShape.addTransition(key, newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
356 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
357 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
358 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
359 protected ShapeImpl cloneRoot(ShapeImpl from, Object newSharedData) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
360 return createShape(from.layout, newSharedData, null, from.objectType, from.propertyMap, from.allocator(), from.id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
361 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
362 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
363 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
364 * Create a separate clone of a shape. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
365 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
366 * @param newParent the cloned parent shape |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
367 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
368 protected final ShapeImpl cloneOnto(ShapeImpl newParent) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
369 ShapeImpl from = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
370 ShapeImpl newShape = createShape(newParent.layout, newParent.sharedData, newParent, from.objectType, from.propertyMap, from.allocator(), newParent.id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
371 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
372 shapeCloneCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
373 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
374 // (aw) need to have this transition for obsolescence |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
375 newParent.addTransition(getTransitionFromParent(), newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
376 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
377 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
378 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
379 private Transition getTransitionFromParent() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
380 for (Map.Entry<Transition, ShapeImpl> property : parent.getTransitionMapForRead().entrySet()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
381 if (property.getValue() == this) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
382 return property.getKey(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
383 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
384 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
385 throw new NoSuchElementException(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
386 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
387 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
388 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
389 * Create a new shape that adds a property to the parent shape. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
390 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
391 private static ShapeImpl makeShapeWithAddedProperty(ShapeImpl parent, AddTransition addTransition) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
392 Property addend = addTransition.getProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
393 BaseAllocator allocator = parent.allocator().addLocation(addend.getLocation()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
394 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
395 PropertyMap newPropertyMap = parent.propertyMap.putCopy(addend); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
396 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
397 ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, newPropertyMap, allocator, parent.id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
398 assert ((LocationImpl) addend.getLocation()).primitiveArrayCount() == 0 || newShape.hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
399 assert newShape.depth == allocator.depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
400 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
401 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
402 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
403 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
404 * Create a new shape that reserves the primitive extension array field. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
405 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
406 private static ShapeImpl makeShapeWithPrimitiveExtensionArray(ShapeImpl parent) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
407 assert parent.getLayout().hasPrimitiveExtensionArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
408 assert !parent.hasPrimitiveArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
409 BaseAllocator allocator = parent.allocator().addLocation(parent.getLayout().getPrimitiveArrayLocation()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
410 ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, parent.propertyMap, allocator, parent.id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
411 assert newShape.hasPrimitiveArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
412 assert newShape.depth == allocator.depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
413 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
414 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
415 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
416 private ShapeImpl addPrimitiveExtensionArray() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
417 assert layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
418 Transition key = new Transition.ReservePrimitiveArrayTransition(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
419 ShapeImpl cachedShape = this.getTransitionMapForRead().get(key); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
420 if (cachedShape != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
421 shapeCacheHitCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
422 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
423 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
424 shapeCacheMissCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
425 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
426 ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
427 ShapeImpl newShape = makeShapeWithPrimitiveExtensionArray(oldShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
428 oldShape.addTransition(key, newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
429 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
430 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
431 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
432 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
433 * Are these two shapes related, i.e. do they have the same root? |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
434 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
435 * @param other Shape to compare to |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
436 * @return true if one shape is an upcast of the other, or the Shapes are equal |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
437 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
438 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
439 public boolean isRelated(Shape other) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
440 if (this == other) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
441 return true; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
442 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
443 if (this.getRoot() == getRoot()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
444 return true; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
445 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
446 return false; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
447 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
448 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
449 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
450 * Get a list of all properties that this Shape stores. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
451 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
452 * @return list of properties |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
453 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
454 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
455 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
456 public final List<Property> getPropertyList(Pred<Property> filter) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
457 LinkedList<Property> props = new LinkedList<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
458 next: for (ShapeImpl current = this; current != getRoot(); current = current.parent) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
459 Property currentProperty = current.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
460 if (!currentProperty.isHidden() && filter.test(currentProperty)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
461 if (currentProperty.getLocation() instanceof DeclaredLocation) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
462 for (Iterator<Property> iter = props.iterator(); iter.hasNext();) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
463 Property other = iter.next(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
464 if (other.isShadow() && other.getKey().equals(currentProperty.getKey())) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
465 iter.remove(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
466 props.addFirst(other); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
467 continue next; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
468 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
469 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
470 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
471 props.addFirst(currentProperty); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
472 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
473 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
474 return props; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
475 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
476 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
477 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
478 public final List<Property> getPropertyList() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
479 return getPropertyList(ALL); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
480 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
481 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
482 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
483 * Returns all (also hidden) Property objects in this shape. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
484 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
485 * @param ascending desired order |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
486 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
487 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
488 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
489 public final List<Property> getPropertyListInternal(boolean ascending) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
490 LinkedList<Property> props = new LinkedList<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
491 for (ShapeImpl current = this; current != getRoot(); current = current.parent) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
492 if (ascending) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
493 props.addFirst(current.getLastProperty()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
494 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
495 props.add(current.getLastProperty()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
496 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
497 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
498 return props; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
499 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
500 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
501 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
502 * Get a list of all (visible) property names in insertion order. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
503 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
504 * @return list of property names |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
505 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
506 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
507 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
508 public final List<Object> getKeyList(Pred<Property> filter) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
509 LinkedList<Object> keys = new LinkedList<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
510 for (ShapeImpl current = this; current != getRoot(); current = current.parent) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
511 Property currentProperty = current.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
512 if (!currentProperty.isHidden() && filter.test(currentProperty) && !currentProperty.isShadow()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
513 keys.addFirst(currentProperty.getKey()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
514 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
515 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
516 return keys; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
517 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
518 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
519 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
520 public final List<Object> getKeyList() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
521 return getKeyList(ALL); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
522 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
523 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
524 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
525 public Iterable<Object> getKeys() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
526 return getKeyList(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
527 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
528 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
529 public final void setTypeTransition(ShapeImpl successorShape, Property before, Property after) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
530 getTransitionMapForWrite().put(new Transition.TypeTransition(before, after), successorShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
531 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
532 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
533 private static Assumption createValidAssumption() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
534 return Truffle.getRuntime().createAssumption("valid shape"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
535 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
536 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
537 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
538 public final Assumption getValidAssumption() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
539 return validAssumption; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
540 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
541 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
542 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
543 public final boolean isValid() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
544 return getValidAssumption().isValid(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
545 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
546 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
547 private static Assumption createLeafAssumption() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
548 return Truffle.getRuntime().createAssumption("leaf shape"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
549 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
550 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
551 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
552 public final Assumption getLeafAssumption() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
553 return leafAssumption; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
554 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
555 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
556 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
557 public final boolean isLeaf() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
558 return getLeafAssumption().isValid(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
559 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
560 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
561 private void invalidateLeafAssumption() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
562 getLeafAssumption().invalidate(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
563 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
564 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
565 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
566 public String toString() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
567 return toStringLimit(Integer.MAX_VALUE); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
568 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
569 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
570 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
571 public String toStringLimit(int limit) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
572 StringBuilder sb = new StringBuilder(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
573 sb.append('@'); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
574 sb.append(Integer.toHexString(hashCode())); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
575 if (!isValid()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
576 sb.append('!'); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
577 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
578 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
579 sb.append("{"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
580 for (Iterator<Property> iterator = propertyMap.reverseOrderValues().iterator(); iterator.hasNext();) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
581 Property p = iterator.next(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
582 sb.append(p); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
583 if (iterator.hasNext()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
584 sb.append(", "); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
585 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
586 if (sb.length() >= limit) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
587 sb.append("..."); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
588 break; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
589 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
590 sb.append("\n"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
591 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
592 sb.append("}"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
593 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
594 return sb.toString(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
595 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
596 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
597 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
598 public final ShapeImpl getParent() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
599 return parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
600 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
601 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
602 public final int getDepth() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
603 return depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
604 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
605 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
606 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
607 public final boolean hasProperty(Object name) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
608 return getProperty(name) != null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
609 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
610 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
611 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
612 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
613 public final ShapeImpl removeProperty(Property prop) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
614 RemoveTransition transition = new RemoveTransition(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
615 ShapeImpl cachedShape = getTransitionMapForRead().get(transition); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
616 if (cachedShape != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
617 return (ShapeImpl) layout.getStrategy().returnCached(cachedShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
618 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
619 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
620 ShapeImpl shape = getShapeFromProperty(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
621 if (shape != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
622 List<Property> properties = new ArrayList<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
623 ShapeImpl current = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
624 while (current != shape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
625 properties.add(current.getLastProperty()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
626 current = current.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
627 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
628 ShapeImpl newShape = shape.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
629 for (ListIterator<Property> iterator = properties.listIterator(properties.size()); iterator.hasPrevious();) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
630 Property previous = iterator.previous(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
631 newShape = newShape.append(previous); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
632 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
633 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
634 getTransitionMapForWrite().put(transition, newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
635 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
636 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
637 return null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
638 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
639 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
640 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
641 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
642 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
643 public final ShapeImpl append(Property oldProperty) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
644 return addProperty(oldProperty.relocate(allocator().moveLocation(oldProperty.getLocation()))); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
645 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
646 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
647 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
648 public final BaseAllocator allocator() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
649 return layout.getStrategy().createAllocator(this); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
650 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
651 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
652 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
653 * Duplicate shape exchanging existing property with new property. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
654 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
655 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
656 public final ShapeImpl replaceProperty(Property oldProperty, Property newProp) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
657 ShapeImpl top = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
658 List<Property> propertyList = new ArrayList<>(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
659 boolean found = false; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
660 while (top != getRoot() && !found) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
661 Property prop = top.getLastProperty(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
662 propertyList.add(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
663 if (prop.getKey().equals(newProp.getKey())) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
664 found = true; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
665 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
666 top = top.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
667 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
668 ShapeImpl newShape = top; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
669 for (ListIterator<Property> iterator = propertyList.listIterator(propertyList.size()); iterator.hasPrevious();) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
670 Property prop = iterator.previous(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
671 if (prop.getKey().equals(newProp.getKey())) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
672 newShape = newShape.addProperty(newProp); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
673 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
674 newShape = newShape.addProperty(prop); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
675 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
676 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
677 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
678 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
679 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
680 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
681 * Find lowest common ancestor of two related shapes. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
682 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
683 public static ShapeImpl findCommonAncestor(ShapeImpl left, ShapeImpl right) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
684 if (!left.isRelated(right)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
685 throw new IllegalArgumentException("shapes must have the same root"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
686 } else if (left == right) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
687 return left; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
688 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
689 int leftLength = left.depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
690 int rightLength = right.depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
691 ShapeImpl leftPtr = left; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
692 ShapeImpl rightPtr = right; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
693 while (leftLength > rightLength) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
694 leftPtr = leftPtr.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
695 leftLength--; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
696 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
697 while (rightLength > leftLength) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
698 rightPtr = rightPtr.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
699 rightLength--; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
700 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
701 while (leftPtr != rightPtr) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
702 leftPtr = leftPtr.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
703 rightPtr = rightPtr.parent; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
704 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
705 return leftPtr; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
706 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
707 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
708 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
709 * For copying over properties after exchanging the prototype of an object. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
710 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
711 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
712 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
713 public final ShapeImpl copyOverPropertiesInternal(Shape destination) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
714 assert ((ShapeImpl) destination).getDepth() == 0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
715 List<Property> properties = this.getPropertyListInternal(true); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
716 ShapeImpl newShape = ((ShapeImpl) destination).addPropertiesInternal(properties); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
717 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
718 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
719 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
720 private ShapeImpl addPropertiesInternal(List<Property> properties) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
721 ShapeImpl newShape = this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
722 for (Property p : properties) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
723 newShape = newShape.addPropertyInternal(p); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
724 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
725 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
726 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
727 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
728 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
729 * NB: this is not an accurate property count. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
730 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
731 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
732 public final int getPropertyCount() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
733 return propertyCount; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
734 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
735 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
736 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
737 * Find difference between two shapes. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
738 * |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
739 * @see ObjectStorageOptions#TraceReshape |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
740 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
741 public static List<Property> diff(Shape oldShape, Shape newShape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
742 List<Property> oldList = oldShape.getPropertyListInternal(false); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
743 List<Property> newList = newShape.getPropertyListInternal(false); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
744 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
745 List<Property> diff = new ArrayList<>(oldList); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
746 diff.addAll(newList); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
747 List<Property> intersection = new ArrayList<>(oldList); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
748 intersection.retainAll(newList); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
749 diff.removeAll(intersection); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
750 return diff; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
751 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
752 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
753 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
754 public ObjectType getObjectType() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
755 return objectType; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
756 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
757 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
758 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
759 public ShapeImpl getRoot() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
760 return root; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
761 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
762 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
763 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
764 public final boolean check(DynamicObject subject) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
765 return subject.getShape() == this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
766 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
767 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
768 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
769 public final LayoutImpl getLayout() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
770 return layout; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
771 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
772 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
773 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
774 public final Object getData() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
775 return extraData; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
776 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
777 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
778 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
779 public final Object getSharedData() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
780 return sharedData; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
781 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
782 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
783 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
784 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
785 public final boolean hasTransitionWithKey(Object key) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
786 for (Transition transition : getTransitionMapForRead().keySet()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
787 if (transition instanceof PropertyTransition) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
788 if (((PropertyTransition) transition).getProperty().getKey().equals(key)) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
789 return true; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
790 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
791 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
792 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
793 return false; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
794 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
795 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
796 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
797 * Clone off a separate shape with new shared data. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
798 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
799 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
800 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
801 public final ShapeImpl createSeparateShape(Object newSharedData) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
802 if (parent == null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
803 return cloneRoot(this, newSharedData); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
804 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
805 return this.cloneOnto(parent.createSeparateShape(newSharedData)); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
806 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
807 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
808 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
809 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
810 @TruffleBoundary |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
811 public final ShapeImpl changeType(ObjectType newOps) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
812 OperationsTransition transition = new OperationsTransition(newOps); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
813 ShapeImpl cachedShape = getTransitionMapForRead().get(transition); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
814 if (cachedShape != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
815 return cachedShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
816 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
817 ShapeImpl newShape = createShape(layout, extraData, this, newOps, propertyMap, allocator(), id); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
818 addTransition(transition, newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
819 return newShape; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
820 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
821 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
822 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
823 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
824 public final Shape reservePrimitiveExtensionArray() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
825 if (layout.hasPrimitiveExtensionArray() && !hasPrimitiveArray()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
826 return addPrimitiveExtensionArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
827 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
828 return this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
829 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
830 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
831 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
832 public final Iterable<Property> getProperties() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
833 if (getPropertyCount() != 0 && propertyArray == null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
834 CompilerDirectives.transferToInterpreter(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
835 propertyArray = createPropertiesArray(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
836 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
837 return new Iterable<Property>() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
838 public Iterator<Property> iterator() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
839 return new Iterator<Property>() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
840 private int cursor; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
841 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
842 public boolean hasNext() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
843 return cursor < getPropertyCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
844 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
845 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
846 public Property next() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
847 if (hasNext()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
848 return propertyArray[cursor++]; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
849 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
850 throw new NoSuchElementException(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
851 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
852 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
853 public void remove() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
854 throw new UnsupportedOperationException(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
855 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
856 }; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
857 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
858 }; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
859 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
860 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
861 private Property[] createPropertiesArray() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
862 propertyListAllocCount.inc(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
863 Property[] propertiesArray = new Property[getPropertyCount()]; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
864 List<Property> ownProperties = getPropertyList(ALL); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
865 assert ownProperties.size() == getPropertyCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
866 for (int i = 0; i < getPropertyCount(); i++) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
867 propertiesArray[i] = ownProperties.get(i); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
868 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
869 return propertiesArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
870 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
871 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
872 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
873 public final DynamicObject newInstance() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
874 return layout.newInstance(this); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
875 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
876 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
877 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
878 public final DynamicObjectFactory createFactory() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
879 final List<Property> properties = getPropertyListInternal(true); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
880 for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
881 Property property = iterator.next(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
882 // skip non-instance fields |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
883 assert property.getLocation() != layout.getPrimitiveArrayLocation(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
884 if (property.getLocation() instanceof ValueLocation) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
885 iterator.remove(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
886 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
887 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
888 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
889 return new DynamicObjectFactory() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
890 @CompilationFinal private final PropertyImpl[] instanceFields = properties.toArray(new PropertyImpl[properties.size()]); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
891 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
892 @ExplodeLoop |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
893 public DynamicObject newInstance(Object... initialValues) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
894 DynamicObject store = ShapeImpl.this.newInstance(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
895 for (int i = 0; i < instanceFields.length; i++) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
896 instanceFields[i].setInternal(store, initialValues[i]); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
897 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
898 return store; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
899 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
900 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
901 public Shape getShape() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
902 return ShapeImpl.this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
903 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
904 }; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
905 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
906 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
907 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
908 public Object getMutex() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
909 return getRoot(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
910 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
911 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
912 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
913 public Shape tryMerge(Shape other) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
914 return null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
915 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
916 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
917 public abstract static class BaseAllocator extends Allocator { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
918 protected final LayoutImpl layout; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
919 protected int objectArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
920 protected int objectFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
921 protected int primitiveFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
922 protected int primitiveArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
923 protected boolean hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
924 protected int depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
925 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
926 protected BaseAllocator(LayoutImpl layout) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
927 this.layout = layout; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
928 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
929 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
930 protected BaseAllocator(ShapeImpl shape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
931 this(shape.getLayout()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
932 this.objectArraySize = shape.objectArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
933 this.objectFieldSize = shape.objectFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
934 this.primitiveFieldSize = shape.primitiveFieldSize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
935 this.primitiveArraySize = shape.primitiveArraySize; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
936 this.hasPrimitiveArray = shape.hasPrimitiveArray; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
937 this.depth = shape.depth; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
938 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
939 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
940 protected abstract Location moveLocation(Location oldLocation); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
941 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
942 protected abstract Location newObjectLocation(boolean useFinal, boolean nonNull); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
943 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
944 protected abstract Location newTypedObjectLocation(boolean useFinal, Class<?> type, boolean nonNull); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
945 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
946 protected abstract Location newIntLocation(boolean useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
947 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
948 protected abstract Location newDoubleLocation(boolean useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
949 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
950 protected abstract Location newLongLocation(boolean useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
951 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
952 protected abstract Location newBooleanLocation(boolean useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
953 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
954 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
955 public final Location constantLocation(Object value) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
956 return new ConstantLocation(value); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
957 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
958 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
959 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
960 protected Location locationForValue(Object value, boolean useFinal, boolean nonNull) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
961 if (value instanceof Integer) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
962 return newIntLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
963 } else if (value instanceof Double) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
964 return newDoubleLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
965 } else if (value instanceof Long) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
966 return newLongLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
967 } else if (value instanceof Boolean) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
968 return newBooleanLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
969 } else if (ObjectStorageOptions.TypedObjectLocations && value != null) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
970 return newTypedObjectLocation(useFinal, value.getClass(), nonNull); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
971 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
972 return newObjectLocation(useFinal, nonNull && value != null); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
973 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
974 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
975 protected abstract Location locationForValueUpcast(Object value, Location oldLocation); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
976 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
977 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
978 protected Location locationForType(Class<?> type, boolean useFinal, boolean nonNull) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
979 if (type == int.class) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
980 return newIntLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
981 } else if (type == double.class) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
982 return newDoubleLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
983 } else if (type == long.class) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
984 return newLongLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
985 } else if (type == boolean.class) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
986 return newBooleanLocation(useFinal); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
987 } else if (ObjectStorageOptions.TypedObjectLocations && type != null && type != Object.class) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
988 assert !type.isPrimitive() : "unsupported primitive type"; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
989 return newTypedObjectLocation(useFinal, type, nonNull); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
990 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
991 return newObjectLocation(useFinal, nonNull); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
992 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
993 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
994 protected Location newDualLocation(Class<?> type) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
995 return new DualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), layout, type); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
996 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
997 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
998 protected DualLocation newDualLocationForValue(Object value) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
999 Class<?> initialType = null; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1000 if (value instanceof Integer) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1001 initialType = int.class; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1002 } else if (value instanceof Double) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1003 initialType = double.class; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1004 } else if (value instanceof Boolean) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1005 initialType = boolean.class; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1006 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1007 initialType = Object.class; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1008 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1009 return new DualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), layout, initialType); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1010 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1011 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1012 protected Location newDeclaredDualLocation(Object value) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1013 return new DeclaredDualLocation((InternalLongLocation) newLongLocation(false), (ObjectLocation) newObjectLocation(false, false), value, layout); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1014 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1015 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1016 protected <T extends Location> T advance(T location0) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1017 if (location0 instanceof LocationImpl) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1018 LocationImpl location = (LocationImpl) location0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1019 objectArraySize += location.objectArrayCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1020 primitiveArraySize += location.primitiveArrayCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1021 primitiveFieldSize += location.primitiveFieldCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1022 if (layout.hasPrimitiveExtensionArray()) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1023 hasPrimitiveArray |= location == layout.getPrimitiveArrayLocation() || location.primitiveArrayCount() != 0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1024 objectFieldSize = location == layout.getPrimitiveArrayLocation() ? objectFieldSize : Math.max(objectFieldSize, layout.objectFieldIndex(location) + location.objectFieldCount()); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1025 } else { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1026 assert !hasPrimitiveArray && location.primitiveArrayCount() == 0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1027 objectFieldSize += location.objectFieldCount(); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1028 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1029 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1030 depth++; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1031 return location0; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1032 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1033 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1034 @Override |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1035 public BaseAllocator addLocation(Location location) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1036 advance(location); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1037 return this; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1038 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1039 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1040 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1041 private static void debugRegisterShape(ShapeImpl newShape) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1042 if (ObjectStorageOptions.DumpShapes) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1043 Debug.registerShape(newShape); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1044 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1045 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1046 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1047 /** |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1048 * Match all filter. |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1049 */ |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1050 public static final Pred<Property> ALL = new Pred<Property>() { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1051 public boolean test(Property t) { |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1052 return true; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1053 } |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1054 }; |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1055 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1056 private static final DebugCounter shapeCount = DebugCounter.create("Shapes allocated total"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1057 private static final DebugCounter shapeCloneCount = DebugCounter.create("Shapes allocated cloned"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1058 private static final DebugCounter shapeCacheHitCount = DebugCounter.create("Shape cache hits"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1059 private static final DebugCounter shapeCacheMissCount = DebugCounter.create("Shape cache misses"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1060 |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1061 protected static final DebugCounter propertyListAllocCount = DebugCounter.create("Property lists allocated"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1062 protected static final DebugCounter propertyListShareCount = DebugCounter.create("Property lists shared"); |
2c3666f44855
Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1063 } |