annotate graal/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java @ 21770:c76742cc2c6f

Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 08 Jun 2015 04:50:13 +0200
parents 5f3dda39d205
children 16725287d5af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
1 /*
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, 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.CompilerDirectives.TruffleBoundary;
18747
6db7923af642 OM: DynamicObject extends TruffleObject, add default implementation
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 18677
diff changeset
28 import com.oracle.truffle.api.interop.*;
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
29 import com.oracle.truffle.api.object.*;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
30 import com.oracle.truffle.object.Locations.ValueLocation;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
31 import com.oracle.truffle.object.debug.*;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
32
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
33 public abstract class DynamicObjectImpl extends DynamicObject implements Cloneable {
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
34 private ShapeImpl shape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
35
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
36 public static final DebugCounter reshapeCount = DebugCounter.create("Reshape count");
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
38 public DynamicObjectImpl(Shape shape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
39 assert shape instanceof ShapeImpl;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40 initialize(shape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41 setShape(shape);
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 if (ObjectStorageOptions.Profile) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44 trackObject(this);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
46 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
47
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
48 public Object getTypeIdentifier() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
49 return getShape();
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
52 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53 public ShapeImpl getShape() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
54 return shape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
55 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
56
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
57 protected void setShape(Shape shape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
58 assert shape.getLayout().getType().isInstance(this);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
59 this.shape = (ShapeImpl) shape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
60 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
61
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
62 protected abstract void initialize(Shape initialShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
63
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
64 public final void setShapeAndResize(Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
65 setShapeAndResize(getShape(), newShape);
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
68 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
69 public final void setShapeAndResize(Shape oldShape, Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
70 assert getShape() == oldShape : "wrong old shape";
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
71 if (oldShape != newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
72 setShape(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
73 resizeStore(oldShape, newShape);
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 assert checkExtensionArrayInvariants(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
76 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
77 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
78
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79 /**
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80 * Set shape to an immediate child of the current shape, optionally growing the extension array.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81 * Typically this would add a single property. Cannot shrink or grow more than one property at a
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
82 * time.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
83 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
84 * @see #setShapeAndResize(Shape, Shape)
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
85 */
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
86 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
87 public final void setShapeAndGrow(Shape oldShape, Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
88 assert getShape() == oldShape : "wrong old shape";
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89 if (oldShape != newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90 assert checkSetShape(oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
91
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
92 setShape(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 growStore(oldShape, newShape);
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 assert checkExtensionArrayInvariants(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
98
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
99 /**
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100 * Simpler version of {@link #resizeStore} when the object is only increasing in size.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 */
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102 private void growStore(Shape oldShape, Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
103 growObjectStore(oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 if (((ShapeImpl) newShape).hasPrimitiveArray) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
105 growPrimitiveStore(oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
106 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 protected abstract void growObjectStore(Shape oldShape, Shape newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
111 protected abstract void growPrimitiveStore(Shape oldShape, Shape newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
112
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
113 private void resizeStore(Shape oldShape, Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
114 resizeObjectStore(oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
115 if (((ShapeImpl) newShape).hasPrimitiveArray) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
116 resizePrimitiveStore(oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
117 }
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 protected abstract void resizePrimitiveStore(Shape oldShape, Shape newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
121
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
122 protected abstract void resizeObjectStore(Shape oldShape, Shape newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
123
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
124 /**
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
125 * Check whether fast transition is valid.
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
126 *
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
127 * @see #setShapeAndGrow
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 private boolean checkSetShape(Shape oldShape, Shape newShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
130 Shape currentShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
131 assert oldShape != newShape : "Wrong old shape assumption?";
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
132 assert newShape != currentShape : "Redundant shape change? shape=" + currentShape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
133 // assert oldShape == currentShape || (oldShape.getLastProperty() == ((EnterpriseLayout)
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
134 // oldShape.getLayout()).getPrimitiveArrayProperty() && oldShape.getParent() ==
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
135 // currentShape) : "Out-of-order shape change?" + "\nparentShape=" + currentShape +
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
136 // "\noldShape=" + oldShape + "\nnewShape=" + newShape;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
137 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
138 }
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 /**
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
141 * Check whether the extension arrays are in accordance with the description in the shape.
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 protected abstract boolean checkExtensionArrayInvariants(Shape newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
144
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
145 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
146 protected final DynamicObject clone() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
147 try {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
148 return (DynamicObject) super.clone();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
149 } catch (CloneNotSupportedException e) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
150 throw new IllegalStateException();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
151 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
152 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
153
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
154 protected abstract DynamicObject cloneWithShape(Shape currentShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
155
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
156 void reshapeAfterDelete(final Shape newShape, final Shape deletedParentShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
157 DynamicObject original = this.cloneWithShape(getShape());
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
158 setShapeAndResize(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
159 copyProperties(original, deletedParentShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
160 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
161
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
162 public final void copyProperties(DynamicObject fromObject, Shape ancestor) {
18677
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
163 ShapeImpl fromShape = (ShapeImpl) fromObject.getShape();
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
164 ShapeImpl toShape = getShape();
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
165 assert toShape.isRelated(ancestor);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
166 assert toShape.isValid();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
167 assert ancestor.isValid();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
168 for (; toShape != ancestor; toShape = toShape.getParent()) {
18677
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
169 Transition transitionFromParent = toShape.getTransitionFromParent();
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
170 if (transitionFromParent instanceof Transition.AddPropertyTransition) {
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
171 Property toProperty = ((Transition.AddPropertyTransition) transitionFromParent).getProperty();
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
172 Property fromProperty = fromShape.getProperty(toProperty.getKey());
18677
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
173
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
174 // copy only if property has a location and it's not the same as the source location
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
175 if (toProperty.getLocation() != null && !(toProperty.getLocation() instanceof ValueLocation) && !toProperty.getLocation().equals(fromProperty.getLocation())) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
176 toProperty.setInternal(this, fromProperty.get(fromObject, false));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
177 assert toShape.isValid();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
178 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
179
18677
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
180 if (fromShape.getTransitionFromParent() instanceof Transition.AddPropertyTransition &&
8d8523ed37e3 OM: copy hidden properties, too
Andreas Woess <andreas.woess@jku.at>
parents: 18408
diff changeset
181 ((Transition.AddPropertyTransition) fromShape.getTransitionFromParent()).getProperty() == fromProperty) {
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
182 // no property is looked up twice, so we can skip over to parent
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
183 fromShape = fromShape.getParent();
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 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
186 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
187 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
188
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
189 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
190 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
191 public boolean changeFlags(Object id, int newFlags) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
192 Shape oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
193 Property existing = oldShape.getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
194 if (existing != null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
195 if (existing.getFlags() != newFlags) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
196 Property newProperty = existing.copyWithFlags(newFlags);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
197 Shape newShape = oldShape.replaceProperty(existing, newProperty);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
198 this.setShape(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
199 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
200 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
201 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
202 return false;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
203 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
204 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
205
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
206 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
207 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
208 public boolean changeFlags(Object id, FlagsFunction updateFunction) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
209 Shape oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
210 Property existing = oldShape.getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
211 if (existing != null) {
21652
5f3dda39d205 Truffle: add DynamicObject#containsKey, make flags parameter optional, minor simplifications
Andreas Woess <andreas.woess@oracle.com>
parents: 19336
diff changeset
212 int newFlags = updateFunction.apply(existing.getFlags());
5f3dda39d205 Truffle: add DynamicObject#containsKey, make flags parameter optional, minor simplifications
Andreas Woess <andreas.woess@oracle.com>
parents: 19336
diff changeset
213 if (existing.getFlags() != newFlags) {
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
214 Property newProperty = existing.copyWithFlags(newFlags);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
215 Shape newShape = oldShape.replaceProperty(existing, newProperty);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
216 this.setShape(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
217 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
218 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
219 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
220 return false;
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 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
223
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
224 public String debugDump(int level) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
225 return debugDump(0, level);
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
228 public String debugDump(int level, int levelStop) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
229 List<Property> properties = this.getShape().getPropertyListInternal(true);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
230 StringBuilder sb = new StringBuilder(properties.size() * 10);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
231 sb.append("{\n");
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
232 for (Property property : properties) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
233 indent(sb, level + 1);
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 sb.append(property.getKey());
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
236 sb.append('[').append(property.getLocation()).append(']');
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
237 Object value = property.get(this, false);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
238 if (value instanceof DynamicObjectImpl) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
239 if (level < levelStop) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
240 value = ((DynamicObjectImpl) value).debugDump(level + 1, levelStop);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
241 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
242 value = value.toString();
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 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
245 sb.append(": ");
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
246 sb.append(value);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
247 if (property != properties.get(properties.size() - 1)) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
248 sb.append(",");
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 sb.append("\n");
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
251 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
252 indent(sb, level);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
253 sb.append("}");
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
254 return sb.toString();
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
257 private static StringBuilder indent(StringBuilder sb, int level) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
258 for (int i = 0; i < level; i++) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
259 sb.append(' ');
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 return sb;
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
264 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
265 public String toString() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
266 return getShape().getObjectType().toString(this);
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
269 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
270 public boolean equals(Object obj) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
271 return getShape().getObjectType().equals(this, obj);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
272 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
273
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
274 @Override
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
275 public int hashCode() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
276 return getShape().getObjectType().hashCode(this);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
277 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
278
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
279 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
280 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
281 public Object get(Object id, Object defaultValue) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
282 Property existing = getShape().getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
283 if (existing != null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
284 return existing.get(this, false);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
285 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
286 return defaultValue;
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 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
289
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
290 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
291 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
292 public boolean set(Object id, Object value) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
293 Property existing = getShape().getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
294 if (existing != null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
295 existing.setGeneric(this, value, null);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
296 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
297 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
298 return false;
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
302 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
303 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
304 public void define(Object id, Object value, int flags) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
305 ShapeImpl oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
306 Property existing = oldShape.getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
307 if (existing == null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
308 updateShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
309 oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
310 Shape newShape = oldShape.addProperty(Property.create(id, oldShape.allocator().locationForValue(value, true, true), flags));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
311 updateShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
312 newShape.getLastProperty().setGeneric(this, value, oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
313 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
314 defineExisting(id, value, flags, existing, oldShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
315 }
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
318 private void defineExisting(Object id, Object value, int flags, Property existing, ShapeImpl oldShape) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
319 if (existing.getFlags() == flags) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
320 existing.setGeneric(this, value, null);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
321 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
322 Property newProperty = Property.create(id, oldShape.getLayout().existingLocationForValue(value, existing.getLocation(), oldShape), flags);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
323 Shape newShape = oldShape.replaceProperty(existing, newProperty);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
324 this.setShapeAndResize(newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
325 newProperty.setInternal(this, value);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
326 }
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
329 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
330 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
331 public void define(Object id, Object value, int flags, LocationFactory locationFactory) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
332 ShapeImpl oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
333 Property existing = oldShape.getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
334 if (existing == null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
335 updateShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
336 oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
337 Shape newShape = oldShape.addProperty(Property.create(id, locationFactory.createLocation(oldShape, value), flags));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
338 updateShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
339 newShape.getLastProperty().setGeneric(this, value, oldShape, newShape);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
340 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
341 defineExisting(id, value, flags, existing, oldShape);
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 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
344
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
345 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
346 @TruffleBoundary
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
347 public boolean delete(Object id) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
348 ShapeImpl oldShape = getShape();
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
349 Property existing = oldShape.getProperty(id);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
350 if (existing != null) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
351 ShapeImpl newShape = oldShape.removeProperty(existing);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
352 this.reshapeAfterDelete(newShape, ShapeImpl.findCommonAncestor(oldShape, newShape));
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
353 // TODO ancestor should be the parent of found property's shape
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
354 return true;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
355 } else {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
356 return false;
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
360 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
361 public int size() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
362 return getShape().getPropertyCount();
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
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
365 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
366 public boolean isEmpty() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
367 return size() == 0;
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
368 }
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
369
19336
723142fed324 Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18747
diff changeset
370 @Override
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
371 public final boolean updateShape() {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
372 return getShape().getLayout().getStrategy().updateShape(this);
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
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
375 private static void trackObject(DynamicObject obj) {
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
376 ShapeProfiler.getInstance().track(obj);
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
377 }
18747
6db7923af642 OM: DynamicObject extends TruffleObject, add default implementation
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 18677
diff changeset
378
21770
c76742cc2c6f Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21652
diff changeset
379 @Override
c76742cc2c6f Polishing inter-operability APIs: Exposing only Message, TruffleObject and ForeignAccess-related classes.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21652
diff changeset
380 public ForeignAccess getForeignAccess() {
18747
6db7923af642 OM: DynamicObject extends TruffleObject, add default implementation
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 18677
diff changeset
381 return getShape().getForeignAccessFactory();
6db7923af642 OM: DynamicObject extends TruffleObject, add default implementation
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 18677
diff changeset
382 }
18408
2c3666f44855 Truffle: initial commit of object API implementation
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
383 }