1
1
/*
2
- * Copyright (c) 2017, 2021 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2022 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2013, Regents of the University of California
4
4
*
5
5
* All rights reserved.
30
30
import com .oracle .graal .python .builtins .objects .ints .PInt ;
31
31
import com .oracle .graal .python .nodes .ErrorMessages ;
32
32
import com .oracle .graal .python .nodes .interop .PForeignToPTypeNode ;
33
- import com .oracle .graal .python .nodes .literal .ListLiteralNode ;
34
33
import com .oracle .graal .python .runtime .GilNode ;
35
34
import com .oracle .graal .python .runtime .exception .PException ;
36
35
import com .oracle .graal .python .runtime .sequence .PSequence ;
36
+ import com .oracle .graal .python .runtime .sequence .storage .BasicSequenceStorage ;
37
37
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
38
38
import com .oracle .graal .python .util .OverflowException ;
39
39
import com .oracle .truffle .api .CompilerAsserts ;
51
51
52
52
@ ExportLibrary (InteropLibrary .class )
53
53
public final class PList extends PSequence {
54
- private final ListLiteralNode origin ;
54
+ private final ListOrigin origin ;
55
55
private SequenceStorage store ;
56
56
57
57
public PList (Object cls , Shape instanceShape , SequenceStorage store ) {
@@ -60,7 +60,7 @@ public PList(Object cls, Shape instanceShape, SequenceStorage store) {
60
60
this .store = store ;
61
61
}
62
62
63
- public PList (Object cls , Shape instanceShape , SequenceStorage store , ListLiteralNode origin ) {
63
+ public PList (Object cls , Shape instanceShape , SequenceStorage store , ListOrigin origin ) {
64
64
super (cls , instanceShape );
65
65
this .origin = origin ;
66
66
this .store = store ;
@@ -117,15 +117,15 @@ public final int hashCode() {
117
117
return super .hashCode ();
118
118
}
119
119
120
- public ListLiteralNode getOrigin () {
120
+ public ListOrigin getOrigin () {
121
121
return origin ;
122
122
}
123
123
124
124
@ ExportMessage
125
125
public SourceSection getSourceLocation (@ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
126
126
boolean mustRelease = gil .acquire ();
127
127
try {
128
- ListLiteralNode node = getOrigin ();
128
+ ListOrigin node = getOrigin ();
129
129
SourceSection result = null ;
130
130
if (node != null ) {
131
131
result = node .getSourceSection ();
@@ -229,4 +229,38 @@ public void removeArrayElement(long index,
229
229
gil .release (mustRelease );
230
230
}
231
231
}
232
+
233
+ public interface ListOrigin {
234
+
235
+ /**
236
+ * This class serves the purpose of updating the size estimate for the lists constructed
237
+ * here over time. The estimate is updated slowly, it takes {@link #NUM_DIGITS_POW2} lists
238
+ * to reach a size one larger than the current estimate to increase the estimate for new
239
+ * lists.
240
+ */
241
+ @ CompilerDirectives .ValueType
242
+ public static final class SizeEstimate {
243
+ private static final int NUM_DIGITS = 3 ;
244
+ private static final int NUM_DIGITS_POW2 = 1 << NUM_DIGITS ;
245
+
246
+ @ CompilerDirectives .CompilationFinal private int shiftedStorageSizeEstimate ;
247
+
248
+ public SizeEstimate (int storageSizeEstimate ) {
249
+ shiftedStorageSizeEstimate = storageSizeEstimate * NUM_DIGITS_POW2 ;
250
+ }
251
+
252
+ public int estimate () {
253
+ return shiftedStorageSizeEstimate >> NUM_DIGITS ;
254
+ }
255
+
256
+ public int updateFrom (int newSizeEstimate ) {
257
+ shiftedStorageSizeEstimate = shiftedStorageSizeEstimate + newSizeEstimate - estimate ();
258
+ return shiftedStorageSizeEstimate ;
259
+ }
260
+ }
261
+
262
+ void reportUpdatedCapacity (BasicSequenceStorage newStore );
263
+
264
+ SourceSection getSourceSection ();
265
+ }
232
266
}
0 commit comments