40
40
*/
41
41
package com .oracle .truffle .api .object ;
42
42
43
- import static com .oracle .truffle .api .object .LayoutImpl .ACCESS ;
44
-
43
+ import java .lang .invoke .VarHandle ;
45
44
import java .util .HashMap ;
46
45
import java .util .Map ;
47
46
import java .util .Objects ;
48
47
49
48
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
50
49
51
- @ SuppressWarnings ("deprecation" )
52
50
final class DynamicObjectSupport {
53
51
54
52
private DynamicObjectSupport () {
55
53
}
56
54
55
+ static void setShapeWithStoreFence (DynamicObject object , Shape shape ) {
56
+ if (shape .isShared ()) {
57
+ VarHandle .storeStoreFence ();
58
+ }
59
+ object .setShape (shape );
60
+ }
61
+
57
62
static void ensureCapacity (DynamicObject object , Shape otherShape ) {
58
63
grow (object , object .getShape (), otherShape );
59
64
}
@@ -77,20 +82,20 @@ private static void growObjectStore(DynamicObject object, ShapeImpl thisShape, i
77
82
Object [] newObjectStore = new Object [targetCapacity ];
78
83
if (sourceCapacity != 0 ) {
79
84
int sourceSize = thisShape .getObjectArraySize ();
80
- Object [] oldObjectStore = ACCESS . getObjectArray ( object );
81
- ACCESS .arrayCopy (oldObjectStore , newObjectStore , sourceSize );
85
+ Object [] oldObjectStore = object . getObjectStore ( );
86
+ UnsafeAccess .arrayCopy (oldObjectStore , newObjectStore , sourceSize );
82
87
}
83
- ACCESS . setObjectArray ( object , newObjectStore );
88
+ object . setObjectStore ( newObjectStore );
84
89
}
85
90
86
91
private static void growPrimitiveStore (DynamicObject object , ShapeImpl thisShape , int sourceCapacity , int targetCapacity ) {
87
92
int [] newPrimitiveArray = new int [targetCapacity ];
88
93
if (sourceCapacity != 0 ) {
89
94
int sourceSize = thisShape .getPrimitiveArraySize ();
90
- int [] oldPrimitiveArray = ACCESS . getPrimitiveArray ( object );
91
- ACCESS .arrayCopy (oldPrimitiveArray , newPrimitiveArray , sourceSize );
95
+ int [] oldPrimitiveArray = object . getPrimitiveStore ( );
96
+ UnsafeAccess .arrayCopy (oldPrimitiveArray , newPrimitiveArray , sourceSize );
92
97
}
93
- ACCESS . setPrimitiveArray ( object , newPrimitiveArray );
98
+ object . setPrimitiveStore ( newPrimitiveArray );
94
99
}
95
100
96
101
static void resize (DynamicObject object , Shape thisShape , Shape otherShape ) {
@@ -108,19 +113,19 @@ private static void resizeObjectStore(DynamicObject object, Shape oldShape, Shap
108
113
ShapeImpl newShapeImpl = (ShapeImpl ) newShape ;
109
114
int destinationCapacity = newShapeImpl .getObjectArrayCapacity ();
110
115
if (destinationCapacity == 0 ) {
111
- ACCESS . setObjectArray ( object , null );
116
+ object . setObjectStore ( null );
112
117
} else {
113
118
int sourceCapacity = oldShapeImpl .getObjectArrayCapacity ();
114
119
if (sourceCapacity != destinationCapacity ) {
115
120
int sourceSize = oldShapeImpl .getObjectArraySize ();
116
121
Object [] newObjectStore = new Object [destinationCapacity ];
117
122
if (sourceSize != 0 ) {
118
- Object [] oldObjectStore = ACCESS . getObjectArray ( object );
123
+ Object [] oldObjectStore = object . getObjectStore ( );
119
124
int destinationSize = newShapeImpl .getObjectArraySize ();
120
125
int length = Math .min (sourceSize , destinationSize );
121
- ACCESS .arrayCopy (oldObjectStore , newObjectStore , length );
126
+ UnsafeAccess .arrayCopy (oldObjectStore , newObjectStore , length );
122
127
}
123
- ACCESS . setObjectArray ( object , newObjectStore );
128
+ object . setObjectStore ( newObjectStore );
124
129
}
125
130
}
126
131
}
@@ -131,61 +136,61 @@ private static void resizePrimitiveStore(DynamicObject object, Shape oldShape, S
131
136
assert newShapeImpl .hasPrimitiveArray ();
132
137
int destinationCapacity = newShapeImpl .getPrimitiveArrayCapacity ();
133
138
if (destinationCapacity == 0 ) {
134
- ACCESS . setPrimitiveArray ( object , null );
139
+ object . setPrimitiveStore ( null );
135
140
} else {
136
141
int sourceCapacity = oldShapeImpl .getPrimitiveArrayCapacity ();
137
142
if (sourceCapacity != destinationCapacity ) {
138
143
int sourceSize = oldShapeImpl .getPrimitiveArraySize ();
139
144
int [] newPrimitiveArray = new int [destinationCapacity ];
140
145
if (sourceSize != 0 ) {
141
- int [] oldPrimitiveArray = ACCESS . getPrimitiveArray ( object );
146
+ int [] oldPrimitiveArray = object . getPrimitiveStore ( );
142
147
int destinationSize = newShapeImpl .getPrimitiveArraySize ();
143
148
int length = Math .min (sourceSize , destinationSize );
144
- ACCESS .arrayCopy (oldPrimitiveArray , newPrimitiveArray , length );
149
+ UnsafeAccess .arrayCopy (oldPrimitiveArray , newPrimitiveArray , length );
145
150
}
146
- ACCESS . setPrimitiveArray ( object , newPrimitiveArray );
151
+ object . setPrimitiveStore ( newPrimitiveArray );
147
152
}
148
153
}
149
154
}
150
155
151
156
private static void trimObjectStore (DynamicObject object , Shape thisShape , Shape newShape ) {
152
157
ShapeImpl thisShapeImpl = (ShapeImpl ) thisShape ;
153
158
ShapeImpl newShapeImpl = (ShapeImpl ) newShape ;
154
- Object [] oldObjectStore = ACCESS . getObjectArray ( object );
159
+ Object [] oldObjectStore = object . getObjectStore ( );
155
160
int destinationCapacity = newShapeImpl .getObjectArrayCapacity ();
156
161
if (destinationCapacity == 0 ) {
157
162
if (oldObjectStore != null ) {
158
- ACCESS . setObjectArray ( object , null );
163
+ object . setObjectStore ( null );
159
164
}
160
165
// else nothing to do
161
166
} else {
162
167
int sourceCapacity = thisShapeImpl .getObjectArrayCapacity ();
163
168
if (sourceCapacity > destinationCapacity ) {
164
169
Object [] newObjectStore = new Object [destinationCapacity ];
165
170
int destinationSize = newShapeImpl .getObjectArraySize ();
166
- ACCESS .arrayCopy (oldObjectStore , newObjectStore , destinationSize );
167
- ACCESS . setObjectArray ( object , newObjectStore );
171
+ UnsafeAccess .arrayCopy (oldObjectStore , newObjectStore , destinationSize );
172
+ object . setObjectStore ( newObjectStore );
168
173
}
169
174
}
170
175
}
171
176
172
177
private static void trimPrimitiveStore (DynamicObject object , Shape thisShape , Shape newShape ) {
173
178
ShapeImpl thisShapeImpl = (ShapeImpl ) thisShape ;
174
179
ShapeImpl newShapeImpl = (ShapeImpl ) newShape ;
175
- int [] oldPrimitiveStore = ACCESS . getPrimitiveArray ( object );
180
+ int [] oldPrimitiveStore = object . getPrimitiveStore ( );
176
181
int destinationCapacity = newShapeImpl .getPrimitiveArrayCapacity ();
177
182
if (destinationCapacity == 0 ) {
178
183
if (oldPrimitiveStore != null ) {
179
- ACCESS . setPrimitiveArray ( object , null );
184
+ object . setPrimitiveStore ( null );
180
185
}
181
186
// else nothing to do
182
187
} else {
183
188
int sourceCapacity = thisShapeImpl .getPrimitiveArrayCapacity ();
184
189
if (sourceCapacity > destinationCapacity ) {
185
190
int [] newPrimitiveStore = new int [destinationCapacity ];
186
191
int destinationSize = newShapeImpl .getPrimitiveArraySize ();
187
- ACCESS .arrayCopy (oldPrimitiveStore , newPrimitiveStore , destinationSize );
188
- ACCESS . setPrimitiveArray ( object , newPrimitiveStore );
192
+ UnsafeAccess .arrayCopy (oldPrimitiveStore , newPrimitiveStore , destinationSize );
193
+ object . setPrimitiveStore ( newPrimitiveStore );
189
194
}
190
195
}
191
196
}
0 commit comments