author | attila |
Fri, 21 Mar 2014 17:52:03 +0100 | |
changeset 24727 | 611ba7e2101f |
parent 24726 | 34410e0545b1 |
parent 23084 | 6c5c02d1023a |
child 24763 | 20971b9687ec |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.runtime; |
|
27 |
||
17513 | 28 |
import static jdk.nashorn.internal.runtime.PropertyHashMap.EMPTY_HASHMAP; |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
29 |
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex; |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
30 |
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; |
16147 | 31 |
|
32 |
import java.lang.invoke.SwitchPoint; |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
33 |
import java.lang.ref.SoftReference; |
16147 | 34 |
import java.util.Arrays; |
35 |
import java.util.Collection; |
|
36 |
import java.util.HashMap; |
|
37 |
import java.util.Iterator; |
|
38 |
import java.util.NoSuchElementException; |
|
39 |
import java.util.WeakHashMap; |
|
40 |
||
41 |
/** |
|
42 |
* Map of object properties. The PropertyMap is the "template" for JavaScript object |
|
43 |
* layouts. It contains a map with prototype names as keys and {@link Property} instances |
|
44 |
* as values. A PropertyMap is typically passed to the {@link ScriptObject} constructor |
|
45 |
* to form the seed map for the ScriptObject. |
|
46 |
* <p> |
|
47 |
* All property maps are immutable. If a property is added, modified or removed, the mutator |
|
48 |
* will return a new map. |
|
49 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
50 |
public final class PropertyMap implements Iterable<Object> { |
16147 | 51 |
/** Used for non extensible PropertyMaps, negative logic as the normal case is extensible. See {@link ScriptObject#preventExtensions()} */ |
17513 | 52 |
public static final int NOT_EXTENSIBLE = 0b0000_0001; |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
53 |
/** Does this map contain valid array keys? */ |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
54 |
public static final int CONTAINS_ARRAY_KEYS = 0b0000_0010; |
17513 | 55 |
|
16147 | 56 |
/** Map status flags. */ |
57 |
private int flags; |
|
58 |
||
59 |
/** Map of properties. */ |
|
60 |
private final PropertyHashMap properties; |
|
61 |
||
17513 | 62 |
/** Number of fields in use. */ |
63 |
private int fieldCount; |
|
64 |
||
65 |
/** Number of fields available. */ |
|
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
66 |
private final int fieldMaximum; |
16147 | 67 |
|
68 |
/** Length of spill in use. */ |
|
69 |
private int spillLength; |
|
70 |
||
71 |
/** {@link SwitchPoint}s for gets on inherited properties. */ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
72 |
private HashMap<String, SwitchPoint> protoGetSwitches; |
16147 | 73 |
|
74 |
/** History of maps, used to limit map duplication. */ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
75 |
private WeakHashMap<Property, SoftReference<PropertyMap>> history; |
16147 | 76 |
|
77 |
/** History of prototypes, used to limit map duplication. */ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
78 |
private WeakHashMap<PropertyMap, SoftReference<PropertyMap>> protoHistory; |
16147 | 79 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
80 |
/** property listeners */ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
81 |
private PropertyListeners listeners; |
16147 | 82 |
|
83 |
/** |
|
84 |
* Constructor. |
|
85 |
* |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
86 |
* @param properties A {@link PropertyHashMap} with initial contents. |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
87 |
* @param fieldCount Number of fields in use. |
17513 | 88 |
* @param fieldMaximum Number of fields available. |
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
89 |
* @param spillLength Number of spill slots used. |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
90 |
* @param containsArrayKeys True if properties contain numeric keys |
16147 | 91 |
*/ |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
92 |
private PropertyMap(final PropertyHashMap properties, final int fieldCount, final int fieldMaximum, final int spillLength, final boolean containsArrayKeys) { |
17513 | 93 |
this.properties = properties; |
94 |
this.fieldCount = fieldCount; |
|
95 |
this.fieldMaximum = fieldMaximum; |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
96 |
this.spillLength = spillLength; |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
97 |
if (containsArrayKeys) { |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
98 |
setContainsArrayKeys(); |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
99 |
} |
16147 | 100 |
|
101 |
if (Context.DEBUG) { |
|
102 |
count++; |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Cloning constructor. |
|
108 |
* |
|
109 |
* @param propertyMap Existing property map. |
|
110 |
* @param properties A {@link PropertyHashMap} with a new set of properties. |
|
111 |
*/ |
|
112 |
private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties) { |
|
17513 | 113 |
this.properties = properties; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
114 |
this.flags = propertyMap.flags; |
17513 | 115 |
this.spillLength = propertyMap.spillLength; |
116 |
this.fieldCount = propertyMap.fieldCount; |
|
117 |
this.fieldMaximum = propertyMap.fieldMaximum; |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
118 |
// We inherit the parent property listeners instance. It will be cloned when a new listener is added. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
119 |
this.listeners = propertyMap.listeners; |
16147 | 120 |
|
121 |
if (Context.DEBUG) { |
|
122 |
count++; |
|
123 |
clonedCount++; |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
/** |
|
17513 | 128 |
* Cloning constructor. |
129 |
* |
|
130 |
* @param propertyMap Existing property map. |
|
131 |
*/ |
|
132 |
private PropertyMap(final PropertyMap propertyMap) { |
|
133 |
this(propertyMap, propertyMap.properties); |
|
134 |
} |
|
135 |
||
136 |
/** |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
137 |
* Duplicates this PropertyMap instance. This is used to duplicate 'shared' |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
138 |
* maps {@link PropertyMap} used as process wide singletons. Shared maps are |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
139 |
* duplicated for every global scope object. That way listeners, proto and property |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
140 |
* histories are scoped within a global scope. |
16147 | 141 |
* |
142 |
* @return Duplicated {@link PropertyMap}. |
|
143 |
*/ |
|
144 |
public PropertyMap duplicate() { |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
145 |
if (Context.DEBUG) { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
146 |
duplicatedCount++; |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
147 |
} |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
148 |
return new PropertyMap(this.properties, 0, 0, 0, containsArrayKeys()); |
16147 | 149 |
} |
150 |
||
151 |
/** |
|
152 |
* Public property map allocator. |
|
153 |
* |
|
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
154 |
* <p>It is the caller's responsibility to make sure that {@code properties} does not contain |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
155 |
* properties with keys that are valid array indices.</p> |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
156 |
* |
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
157 |
* @param properties Collection of initial properties. |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
158 |
* @param fieldCount Number of fields in use. |
17513 | 159 |
* @param fieldMaximum Number of fields available. |
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
160 |
* @param spillLength Number of used spill slots. |
16147 | 161 |
* @return New {@link PropertyMap}. |
162 |
*/ |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
163 |
public static PropertyMap newMap(final Collection<Property> properties, final int fieldCount, final int fieldMaximum, final int spillLength) { |
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
164 |
final PropertyHashMap newProperties = EMPTY_HASHMAP.immutableAdd(properties); |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
165 |
return new PropertyMap(newProperties, fieldCount, fieldMaximum, spillLength, false); |
16147 | 166 |
} |
167 |
||
168 |
/** |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
169 |
* Public property map allocator. Used by nasgen generated code. |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
170 |
* |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
171 |
* <p>It is the caller's responsibility to make sure that {@code properties} does not contain |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
172 |
* properties with keys that are valid array indices.</p> |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
173 |
* |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
174 |
* @param properties Collection of initial properties. |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
175 |
* @return New {@link PropertyMap}. |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
176 |
*/ |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
177 |
public static PropertyMap newMap(final Collection<Property> properties) { |
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
178 |
return properties == null || properties.isEmpty()? newMap() : newMap(properties, 0, 0, 0); |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
179 |
} |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
180 |
|
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
181 |
/** |
16147 | 182 |
* Return a sharable empty map. |
183 |
* |
|
184 |
* @return New empty {@link PropertyMap}. |
|
185 |
*/ |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18618
diff
changeset
|
186 |
public static PropertyMap newMap() { |
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
187 |
return new PropertyMap(EMPTY_HASHMAP, 0, 0, 0, false); |
16147 | 188 |
} |
189 |
||
190 |
/** |
|
191 |
* Return number of properties in the map. |
|
192 |
* |
|
193 |
* @return Number of properties. |
|
194 |
*/ |
|
195 |
public int size() { |
|
196 |
return properties.size(); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
200 |
* Get the listeners of this map, or null if none exists |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
201 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
202 |
* @return the listeners |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
203 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
204 |
public PropertyListeners getListeners() { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
205 |
return listeners; |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
206 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
207 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
208 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
209 |
* Add {@code listenerMap} as a listener to this property map for the given {@code key}. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
210 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
211 |
* @param key the property name |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
212 |
* @param listenerMap the listener map |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
213 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
214 |
public void addListener(final String key, final PropertyMap listenerMap) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
215 |
if (listenerMap != this) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
216 |
// We need to clone listener instance when adding a new listener since we share |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
217 |
// the listeners instance with our parent maps that don't need to see the new listener. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
218 |
listeners = PropertyListeners.addListener(listeners, key, listenerMap); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
219 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
220 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
221 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
222 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
223 |
* A new property is being added. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
224 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
225 |
* @param property The new Property added. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
226 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
227 |
public void propertyAdded(final Property property) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
228 |
invalidateProtoGetSwitchPoint(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
229 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
230 |
listeners.propertyAdded(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
231 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
232 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
233 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
234 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
235 |
* An existing property is being deleted. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
236 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
237 |
* @param property The property being deleted. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
238 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
239 |
public void propertyDeleted(final Property property) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
240 |
invalidateProtoGetSwitchPoint(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
241 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
242 |
listeners.propertyDeleted(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
243 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
244 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
245 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
246 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
247 |
* An existing property is being redefined. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
248 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
249 |
* @param oldProperty The old property |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
250 |
* @param newProperty The new property |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
251 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
252 |
public void propertyModified(final Property oldProperty, final Property newProperty) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
253 |
invalidateProtoGetSwitchPoint(oldProperty); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
254 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
255 |
listeners.propertyModified(oldProperty, newProperty); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
256 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
257 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
258 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
259 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
260 |
* The prototype of an object associated with this {@link PropertyMap} is changed. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
261 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
262 |
public void protoChanged() { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
263 |
invalidateAllProtoGetSwitchPoints(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
264 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
265 |
listeners.protoChanged(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
266 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
267 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
268 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
269 |
/** |
16147 | 270 |
* Return a SwitchPoint used to track changes of a property in a prototype. |
271 |
* |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
272 |
* @param key Property key. |
16147 | 273 |
* @return A shared {@link SwitchPoint} for the property. |
274 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
275 |
public synchronized SwitchPoint getSwitchPoint(final String key) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
276 |
if (protoGetSwitches == null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
277 |
protoGetSwitches = new HashMap<>(); |
16147 | 278 |
} |
279 |
||
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
280 |
SwitchPoint switchPoint = protoGetSwitches.get(key); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
281 |
if (switchPoint == null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
282 |
switchPoint = new SwitchPoint(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
283 |
protoGetSwitches.put(key, switchPoint); |
16147 | 284 |
} |
285 |
||
286 |
return switchPoint; |
|
287 |
} |
|
288 |
||
289 |
/** |
|
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
290 |
* Indicate that a prototype property has changed. |
16147 | 291 |
* |
292 |
* @param property {@link Property} to invalidate. |
|
293 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
294 |
synchronized void invalidateProtoGetSwitchPoint(final Property property) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
295 |
if (protoGetSwitches != null) { |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
296 |
|
16147 | 297 |
final String key = property.getKey(); |
298 |
final SwitchPoint sp = protoGetSwitches.get(key); |
|
299 |
if (sp != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
300 |
protoGetSwitches.remove(key); |
16147 | 301 |
if (Context.DEBUG) { |
302 |
protoInvalidations++; |
|
303 |
} |
|
304 |
SwitchPoint.invalidateAll(new SwitchPoint[] { sp }); |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
/** |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
310 |
* Indicate that proto itself has changed in hierarchy somewhere. |
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
311 |
*/ |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
312 |
synchronized void invalidateAllProtoGetSwitchPoints() { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
313 |
if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
314 |
if (Context.DEBUG) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
315 |
protoInvalidations += protoGetSwitches.size(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
316 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
317 |
SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()])); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
318 |
protoGetSwitches.clear(); |
19619
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
319 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
320 |
} |
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
321 |
|
4085b74056ee
8023368: Instance __proto__ property should exist and be writable.
sundar
parents:
19097
diff
changeset
|
322 |
/** |
16147 | 323 |
* Add a property to the map, re-binding its getters and setters, |
324 |
* if available, to a given receiver. This is typically the global scope. See |
|
325 |
* {@link ScriptObject#addBoundProperties(ScriptObject)} |
|
326 |
* |
|
327 |
* @param property {@link Property} being added. |
|
328 |
* @param bindTo Object to bind to. |
|
329 |
* |
|
330 |
* @return New {@link PropertyMap} with {@link Property} added. |
|
331 |
*/ |
|
18860
e387fde9322a
8014785: Ability to extend global instance by binding properties of another object
sundar
parents:
18855
diff
changeset
|
332 |
PropertyMap addPropertyBind(final AccessorProperty property, final Object bindTo) { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
333 |
// No need to store bound property in the history as bound properties can't be reused. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
334 |
return addPropertyNoHistory(new AccessorProperty(property, bindTo)); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
335 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
336 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
337 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
338 |
* Add a property to the map without adding it to the history. This should be used for properties that |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
339 |
* can't be shared such as bound properties, or properties that are expected to be added only once. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
340 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
341 |
* @param property {@link Property} being added. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
342 |
* @return New {@link PropertyMap} with {@link Property} added. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
343 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
344 |
public PropertyMap addPropertyNoHistory(final Property property) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
345 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
346 |
listeners.propertyAdded(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
347 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
348 |
final PropertyHashMap newProperties = properties.immutableAdd(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
349 |
final PropertyMap newMap = new PropertyMap(this, newProperties); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
350 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
351 |
if(!property.isSpill()) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
352 |
newMap.fieldCount = Math.max(newMap.fieldCount, property.getSlot() + 1); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
353 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
354 |
if (isValidArrayIndex(getArrayIndex(property.getKey()))) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
355 |
newMap.setContainsArrayKeys(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
356 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
357 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
358 |
newMap.spillLength += property.getSpillCount(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
359 |
return newMap; |
16147 | 360 |
} |
361 |
||
362 |
/** |
|
363 |
* Add a property to the map. Cloning or using an existing map if available. |
|
364 |
* |
|
365 |
* @param property {@link Property} being added. |
|
366 |
* |
|
367 |
* @return New {@link PropertyMap} with {@link Property} added. |
|
368 |
*/ |
|
18617
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
369 |
public PropertyMap addProperty(final Property property) { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
370 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
371 |
listeners.propertyAdded(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
372 |
} |
16147 | 373 |
PropertyMap newMap = checkHistory(property); |
374 |
||
375 |
if (newMap == null) { |
|
376 |
final PropertyHashMap newProperties = properties.immutableAdd(property); |
|
377 |
newMap = new PropertyMap(this, newProperties); |
|
378 |
addToHistory(property, newMap); |
|
17513 | 379 |
|
24719 | 380 |
if (!property.isSpill()) { |
17513 | 381 |
newMap.fieldCount = Math.max(newMap.fieldCount, property.getSlot() + 1); |
382 |
} |
|
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
383 |
if (isValidArrayIndex(getArrayIndex(property.getKey()))) { |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
384 |
newMap.setContainsArrayKeys(); |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
385 |
} |
17513 | 386 |
|
16147 | 387 |
newMap.spillLength += property.getSpillCount(); |
388 |
} |
|
389 |
||
390 |
return newMap; |
|
391 |
} |
|
392 |
||
393 |
/** |
|
394 |
* Remove a property from a map. Cloning or using an existing map if available. |
|
395 |
* |
|
396 |
* @param property {@link Property} being removed. |
|
397 |
* |
|
398 |
* @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found. |
|
399 |
*/ |
|
16228 | 400 |
public PropertyMap deleteProperty(final Property property) { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
401 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
402 |
listeners.propertyDeleted(property); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
403 |
} |
16147 | 404 |
PropertyMap newMap = checkHistory(property); |
405 |
final String key = property.getKey(); |
|
406 |
||
407 |
if (newMap == null && properties.containsKey(key)) { |
|
408 |
final PropertyHashMap newProperties = properties.immutableRemove(key); |
|
409 |
newMap = new PropertyMap(this, newProperties); |
|
410 |
addToHistory(property, newMap); |
|
411 |
} |
|
412 |
||
413 |
return newMap; |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Replace an existing property with a new one. |
|
418 |
* |
|
419 |
* @param oldProperty Property to replace. |
|
420 |
* @param newProperty New {@link Property}. |
|
421 |
* |
|
422 |
* @return New {@link PropertyMap} with {@link Property} replaced. |
|
423 |
*/ |
|
424 |
PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
425 |
if (listeners != null) { |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
426 |
listeners.propertyModified(oldProperty, newProperty); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
427 |
} |
16147 | 428 |
// Add replaces existing property. |
24719 | 429 |
final PropertyHashMap newProperties = properties.immutableReplace(oldProperty, newProperty); |
16147 | 430 |
final PropertyMap newMap = new PropertyMap(this, newProperties); |
431 |
/* |
|
432 |
* See ScriptObject.modifyProperty and ScriptObject.setUserAccessors methods. |
|
433 |
* |
|
434 |
* This replaceProperty method is called only for the following three cases: |
|
435 |
* |
|
436 |
* 1. To change flags OR TYPE of an old (cloned) property. We use the same spill slots. |
|
437 |
* 2. To change one UserAccessor property with another - user getter or setter changed via |
|
438 |
* Object.defineProperty function. Again, same spill slots are re-used. |
|
439 |
* 3. Via ScriptObject.setUserAccessors method to set user getter and setter functions |
|
440 |
* replacing the dummy AccessorProperty with null method handles (added during map init). |
|
441 |
* |
|
442 |
* In case (1) and case(2), the property type of old and new property is same. For case (3), |
|
443 |
* the old property is an AccessorProperty and the new one is a UserAccessorProperty property. |
|
444 |
*/ |
|
445 |
||
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
446 |
final boolean sameType = oldProperty.getClass() == newProperty.getClass(); |
16147 | 447 |
assert sameType || |
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
448 |
oldProperty instanceof AccessorProperty && |
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
449 |
newProperty instanceof UserAccessorProperty : |
24719 | 450 |
"arbitrary replaceProperty attempted " + sameType + " oldProperty=" + oldProperty.getClass() + " newProperty=" + newProperty.getClass() + " [" + oldProperty.getCurrentType() + " => " + newProperty.getCurrentType() + "]"; |
16147 | 451 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
452 |
newMap.flags = flags; |
16147 | 453 |
|
454 |
/* |
|
455 |
* spillLength remains same in case (1) and (2) because of slot reuse. Only for case (3), we need |
|
456 |
* to add spill count of the newly added UserAccessorProperty property. |
|
457 |
*/ |
|
24719 | 458 |
newMap.spillLength = spillLength; |
16147 | 459 |
return newMap; |
460 |
} |
|
461 |
||
19097
f544a2ea40ef
8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents:
18860
diff
changeset
|
462 |
/** |
18617
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
463 |
* Make a new UserAccessorProperty property. getter and setter functions are stored in |
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
464 |
* this ScriptObject and slot values are used in property object. Note that slots |
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
465 |
* are assigned speculatively and should be added to map before adding other |
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
466 |
* properties. |
19097
f544a2ea40ef
8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents:
18860
diff
changeset
|
467 |
* |
f544a2ea40ef
8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents:
18860
diff
changeset
|
468 |
* @param key the property name |
f544a2ea40ef
8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents:
18860
diff
changeset
|
469 |
* @param propertyFlags attribute flags of the property |
f544a2ea40ef
8021262: Make nashorn access checks consistent with underlying dynalink
sundar
parents:
18860
diff
changeset
|
470 |
* @return the newly created UserAccessorProperty |
18617
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
471 |
*/ |
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
472 |
public UserAccessorProperty newUserAccessors(final String key, final int propertyFlags) { |
24719 | 473 |
return new UserAccessorProperty(key, propertyFlags, spillLength); |
18617
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
474 |
} |
f6fe338f62c3
8008458: Strict functions dont share property map
jlaskey
parents:
18325
diff
changeset
|
475 |
|
16147 | 476 |
/** |
477 |
* Find a property in the map. |
|
478 |
* |
|
479 |
* @param key Key to search for. |
|
480 |
* |
|
481 |
* @return {@link Property} matching key. |
|
482 |
*/ |
|
483 |
public Property findProperty(final String key) { |
|
484 |
return properties.find(key); |
|
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* Adds all map properties from another map. |
|
489 |
* |
|
490 |
* @param other The source of properties. |
|
491 |
* |
|
492 |
* @return New {@link PropertyMap} with added properties. |
|
493 |
*/ |
|
494 |
public PropertyMap addAll(final PropertyMap other) { |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16201
diff
changeset
|
495 |
assert this != other : "adding property map to itself"; |
16147 | 496 |
final Property[] otherProperties = other.properties.getProperties(); |
497 |
final PropertyHashMap newProperties = properties.immutableAdd(otherProperties); |
|
498 |
||
499 |
final PropertyMap newMap = new PropertyMap(this, newProperties); |
|
500 |
for (final Property property : otherProperties) { |
|
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
501 |
if (isValidArrayIndex(getArrayIndex(property.getKey()))) { |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
502 |
newMap.setContainsArrayKeys(); |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
503 |
} |
16147 | 504 |
newMap.spillLength += property.getSpillCount(); |
505 |
} |
|
506 |
||
507 |
return newMap; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Return an array of all properties. |
|
512 |
* |
|
513 |
* @return Properties as an array. |
|
514 |
*/ |
|
515 |
public Property[] getProperties() { |
|
516 |
return properties.getProperties(); |
|
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Prevents the map from having additional properties. |
|
521 |
* |
|
522 |
* @return New map with {@link #NOT_EXTENSIBLE} flag set. |
|
523 |
*/ |
|
524 |
PropertyMap preventExtensions() { |
|
17513 | 525 |
final PropertyMap newMap = new PropertyMap(this); |
16147 | 526 |
newMap.flags |= NOT_EXTENSIBLE; |
527 |
return newMap; |
|
528 |
} |
|
529 |
||
530 |
/** |
|
531 |
* Prevents properties in map from being modified. |
|
532 |
* |
|
16154
de44634fa4ec
8005782: get rid of javadoc errors, warnings in nashorn build
sundar
parents:
16152
diff
changeset
|
533 |
* @return New map with {@link #NOT_EXTENSIBLE} flag set and properties with |
de44634fa4ec
8005782: get rid of javadoc errors, warnings in nashorn build
sundar
parents:
16152
diff
changeset
|
534 |
* {@link Property#NOT_CONFIGURABLE} set. |
16147 | 535 |
*/ |
536 |
PropertyMap seal() { |
|
17513 | 537 |
PropertyHashMap newProperties = EMPTY_HASHMAP; |
16147 | 538 |
|
539 |
for (final Property oldProperty : properties.getProperties()) { |
|
540 |
newProperties = newProperties.immutableAdd(oldProperty.addFlags(Property.NOT_CONFIGURABLE)); |
|
541 |
} |
|
542 |
||
543 |
final PropertyMap newMap = new PropertyMap(this, newProperties); |
|
544 |
newMap.flags |= NOT_EXTENSIBLE; |
|
545 |
||
546 |
return newMap; |
|
547 |
} |
|
548 |
||
549 |
/** |
|
550 |
* Prevents properties in map from being modified or written to. |
|
551 |
* |
|
552 |
* @return New map with {@link #NOT_EXTENSIBLE} flag set and properties with |
|
16154
de44634fa4ec
8005782: get rid of javadoc errors, warnings in nashorn build
sundar
parents:
16152
diff
changeset
|
553 |
* {@link Property#NOT_CONFIGURABLE} and {@link Property#NOT_WRITABLE} set. |
16147 | 554 |
*/ |
555 |
PropertyMap freeze() { |
|
17513 | 556 |
PropertyHashMap newProperties = EMPTY_HASHMAP; |
16147 | 557 |
|
24721
81f70e23cd3b
8036127: Prototype filter needs to be applied to getter guard as well, not just getter
lagergren
parents:
24719
diff
changeset
|
558 |
for (final Property oldProperty : properties.getProperties()) { |
16147 | 559 |
int propertyFlags = Property.NOT_CONFIGURABLE; |
560 |
||
561 |
if (!(oldProperty instanceof UserAccessorProperty)) { |
|
562 |
propertyFlags |= Property.NOT_WRITABLE; |
|
563 |
} |
|
564 |
||
565 |
newProperties = newProperties.immutableAdd(oldProperty.addFlags(propertyFlags)); |
|
566 |
} |
|
567 |
||
568 |
final PropertyMap newMap = new PropertyMap(this, newProperties); |
|
569 |
newMap.flags |= NOT_EXTENSIBLE; |
|
570 |
||
571 |
return newMap; |
|
572 |
} |
|
573 |
||
574 |
/** |
|
575 |
* Check for any configurable properties. |
|
576 |
* |
|
577 |
* @return {@code true} if any configurable. |
|
578 |
*/ |
|
579 |
private boolean anyConfigurable() { |
|
580 |
for (final Property property : properties.getProperties()) { |
|
581 |
if (property.isConfigurable()) { |
|
582 |
return true; |
|
583 |
} |
|
584 |
} |
|
585 |
||
586 |
return false; |
|
587 |
} |
|
588 |
||
589 |
/** |
|
590 |
* Check if all properties are frozen. |
|
591 |
* |
|
592 |
* @return {@code true} if all are frozen. |
|
593 |
*/ |
|
594 |
private boolean allFrozen() { |
|
595 |
for (final Property property : properties.getProperties()) { |
|
596 |
// check if it is a data descriptor |
|
597 |
if (!(property instanceof UserAccessorProperty)) { |
|
598 |
if (property.isWritable()) { |
|
599 |
return false; |
|
600 |
} |
|
601 |
} |
|
602 |
if (property.isConfigurable()) { |
|
603 |
return false; |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
return true; |
|
608 |
} |
|
609 |
||
610 |
/** |
|
611 |
* Check prototype history for an existing property map with specified prototype. |
|
612 |
* |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
613 |
* @param parentMap New prototype object. |
16147 | 614 |
* |
615 |
* @return Existing {@link PropertyMap} or {@code null} if not found. |
|
616 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
617 |
private PropertyMap checkProtoHistory(final PropertyMap parentMap) { |
16147 | 618 |
final PropertyMap cachedMap; |
619 |
if (protoHistory != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
620 |
final SoftReference<PropertyMap> weakMap = protoHistory.get(parentMap); |
16147 | 621 |
cachedMap = (weakMap != null ? weakMap.get() : null); |
622 |
} else { |
|
623 |
cachedMap = null; |
|
624 |
} |
|
625 |
||
626 |
if (Context.DEBUG && cachedMap != null) { |
|
627 |
protoHistoryHit++; |
|
628 |
} |
|
629 |
||
630 |
return cachedMap; |
|
631 |
} |
|
632 |
||
633 |
/** |
|
634 |
* Add a map to the prototype history. |
|
635 |
* |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
636 |
* @param parentMap Prototype to add (key.) |
16147 | 637 |
* @param newMap {@link PropertyMap} associated with prototype. |
638 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
639 |
private void addToProtoHistory(final PropertyMap parentMap, final PropertyMap newMap) { |
16759
ecf99910fc31
8011219: Regression with recent PropertyMap history changes
hannesw
parents:
16758
diff
changeset
|
640 |
if (protoHistory == null) { |
ecf99910fc31
8011219: Regression with recent PropertyMap history changes
hannesw
parents:
16758
diff
changeset
|
641 |
protoHistory = new WeakHashMap<>(); |
ecf99910fc31
8011219: Regression with recent PropertyMap history changes
hannesw
parents:
16758
diff
changeset
|
642 |
} |
16758
4f7379c41907
8011095: PropertyHashMap.rehash() does not grow enough
jlaskey
parents:
16275
diff
changeset
|
643 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
644 |
protoHistory.put(parentMap, new SoftReference<>(newMap)); |
16147 | 645 |
} |
646 |
||
647 |
/** |
|
648 |
* Track the modification of the map. |
|
649 |
* |
|
650 |
* @param property Mapping property. |
|
651 |
* @param newMap Modified {@link PropertyMap}. |
|
652 |
*/ |
|
653 |
private void addToHistory(final Property property, final PropertyMap newMap) { |
|
16774
745fe7d2536d
8011540: PropertyMap histories should not begin with empty map
jlaskey
parents:
16759
diff
changeset
|
654 |
if (!properties.isEmpty()) { |
745fe7d2536d
8011540: PropertyMap histories should not begin with empty map
jlaskey
parents:
16759
diff
changeset
|
655 |
if (history == null) { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
656 |
history = new WeakHashMap<>(); |
16774
745fe7d2536d
8011540: PropertyMap histories should not begin with empty map
jlaskey
parents:
16759
diff
changeset
|
657 |
} |
745fe7d2536d
8011540: PropertyMap histories should not begin with empty map
jlaskey
parents:
16759
diff
changeset
|
658 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
659 |
history.put(property, new SoftReference<>(newMap)); |
16759
ecf99910fc31
8011219: Regression with recent PropertyMap history changes
hannesw
parents:
16758
diff
changeset
|
660 |
} |
16147 | 661 |
} |
662 |
||
663 |
/** |
|
664 |
* Check the history for a map that already has the given property added. |
|
665 |
* |
|
666 |
* @param property {@link Property} to add. |
|
667 |
* |
|
668 |
* @return Existing map or {@code null} if not found. |
|
669 |
*/ |
|
670 |
private PropertyMap checkHistory(final Property property) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
671 |
|
16147 | 672 |
if (history != null) { |
24727 | 673 |
final SoftReference<PropertyMap> ref = history.get(property); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
674 |
final PropertyMap historicMap = ref == null ? null : ref.get(); |
16147 | 675 |
|
676 |
if (historicMap != null) { |
|
677 |
if (Context.DEBUG) { |
|
678 |
historyHit++; |
|
679 |
} |
|
680 |
||
681 |
return historicMap; |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
return null; |
|
686 |
} |
|
687 |
||
688 |
/** |
|
24719 | 689 |
* Returns true if the two maps have identical properties in the same order, but allows the properties to differ in |
690 |
* their types. This method is mostly useful for tests. |
|
691 |
* @param otherMap the other map |
|
692 |
* @return true if this map has identical properties in the same order as the other map, allowing the properties to |
|
693 |
* differ in type. |
|
694 |
*/ |
|
695 |
public boolean equalsWithoutType(final PropertyMap otherMap) { |
|
696 |
if (properties.size() != otherMap.properties.size()) { |
|
697 |
return false; |
|
698 |
} |
|
699 |
||
700 |
final Iterator<Property> iter = properties.values().iterator(); |
|
701 |
final Iterator<Property> otherIter = otherMap.properties.values().iterator(); |
|
702 |
||
703 |
while (iter.hasNext() && otherIter.hasNext()) { |
|
704 |
if (!iter.next().equalsWithoutType(otherIter.next())) { |
|
705 |
return false; |
|
706 |
} |
|
707 |
} |
|
708 |
||
709 |
return true; |
|
710 |
} |
|
711 |
||
16147 | 712 |
@Override |
713 |
public String toString() { |
|
714 |
final StringBuilder sb = new StringBuilder(); |
|
715 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24721
diff
changeset
|
716 |
sb.append(Debug.id(this)); |
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24721
diff
changeset
|
717 |
sb.append(" = {\n"); |
16147 | 718 |
|
24726
34410e0545b1
8037967: Broke the build, by commiting without saving the last review comment
lagergren
parents:
24725
diff
changeset
|
719 |
for (final Property property : getProperties()) { |
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24721
diff
changeset
|
720 |
sb.append('\t'); |
24719 | 721 |
sb.append(property); |
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24721
diff
changeset
|
722 |
sb.append('\n'); |
16147 | 723 |
} |
724 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24721
diff
changeset
|
725 |
sb.append('}'); |
16147 | 726 |
|
727 |
return sb.toString(); |
|
728 |
} |
|
729 |
||
730 |
@Override |
|
731 |
public Iterator<Object> iterator() { |
|
732 |
return new PropertyMapIterator(this); |
|
733 |
} |
|
734 |
||
735 |
/** |
|
21441
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
736 |
* Check if this map contains properties with valid array keys |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
737 |
* |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
738 |
* @return {@code true} if this map contains properties with valid array keys |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
739 |
*/ |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
740 |
public final boolean containsArrayKeys() { |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
741 |
return (flags & CONTAINS_ARRAY_KEYS) != 0; |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
742 |
} |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
743 |
|
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
744 |
/** |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
745 |
* Flag this object as having array keys in defined properties |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
746 |
*/ |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
747 |
private void setContainsArrayKeys() { |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
748 |
flags |= CONTAINS_ARRAY_KEYS; |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
749 |
} |
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
750 |
|
0b98be59e3cb
8026858: Array length does not handle defined properties correctly
hannesw
parents:
19619
diff
changeset
|
751 |
/** |
16147 | 752 |
* Test to see if {@link PropertyMap} is extensible. |
753 |
* |
|
754 |
* @return {@code true} if {@link PropertyMap} can be added to. |
|
755 |
*/ |
|
756 |
boolean isExtensible() { |
|
757 |
return (flags & NOT_EXTENSIBLE) == 0; |
|
758 |
} |
|
759 |
||
760 |
/** |
|
761 |
* Test to see if {@link PropertyMap} is not extensible or any properties |
|
762 |
* can not be modified. |
|
763 |
* |
|
764 |
* @return {@code true} if {@link PropertyMap} is sealed. |
|
765 |
*/ |
|
766 |
boolean isSealed() { |
|
767 |
return !isExtensible() && !anyConfigurable(); |
|
768 |
} |
|
769 |
||
770 |
/** |
|
771 |
* Test to see if {@link PropertyMap} is not extensible or all properties |
|
772 |
* can not be modified. |
|
773 |
* |
|
774 |
* @return {@code true} if {@link PropertyMap} is frozen. |
|
775 |
*/ |
|
776 |
boolean isFrozen() { |
|
777 |
return !isExtensible() && allFrozen(); |
|
778 |
} |
|
17513 | 779 |
/** |
780 |
* Get the number of fields allocated for this {@link PropertyMap}. |
|
781 |
* |
|
782 |
* @return Number of fields allocated. |
|
783 |
*/ |
|
784 |
int getFieldCount() { |
|
785 |
return fieldCount; |
|
786 |
} |
|
787 |
/** |
|
788 |
* Get maximum number of fields available for this {@link PropertyMap}. |
|
789 |
* |
|
790 |
* @return Number of fields available. |
|
791 |
*/ |
|
792 |
int getFieldMaximum() { |
|
793 |
return fieldMaximum; |
|
794 |
} |
|
16147 | 795 |
|
796 |
/** |
|
797 |
* Get length of spill area associated with this {@link PropertyMap}. |
|
798 |
* |
|
799 |
* @return Length of spill area. |
|
800 |
*/ |
|
801 |
int getSpillLength() { |
|
802 |
return spillLength; |
|
803 |
} |
|
804 |
||
805 |
/** |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
806 |
* Return a property map with the same layout that is associated with the new prototype object. |
16147 | 807 |
* |
17513 | 808 |
* @param newProto New prototype object to replace oldProto. |
16147 | 809 |
* @return New {@link PropertyMap} with prototype changed. |
810 |
*/ |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
811 |
public PropertyMap changeProto(final ScriptObject newProto) { |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
812 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
813 |
final PropertyMap parentMap = newProto == null ? null : newProto.getMap(); |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
814 |
final PropertyMap nextMap = checkProtoHistory(parentMap); |
16147 | 815 |
if (nextMap != null) { |
816 |
return nextMap; |
|
817 |
} |
|
818 |
||
819 |
if (Context.DEBUG) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
820 |
setProtoNewMapCount++; |
16147 | 821 |
} |
17513 | 822 |
|
823 |
final PropertyMap newMap = new PropertyMap(this); |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
21441
diff
changeset
|
824 |
addToProtoHistory(parentMap, newMap); |
16147 | 825 |
|
826 |
return newMap; |
|
827 |
} |
|
828 |
||
829 |
||
830 |
/** |
|
831 |
* {@link PropertyMap} iterator. |
|
832 |
*/ |
|
833 |
private static class PropertyMapIterator implements Iterator<Object> { |
|
834 |
/** Property iterator. */ |
|
835 |
final Iterator<Property> iter; |
|
836 |
||
837 |
/** Current Property. */ |
|
838 |
Property property; |
|
839 |
||
840 |
/** |
|
841 |
* Constructor. |
|
842 |
* |
|
843 |
* @param propertyMap {@link PropertyMap} to iterate over. |
|
844 |
*/ |
|
845 |
PropertyMapIterator(final PropertyMap propertyMap) { |
|
846 |
iter = Arrays.asList(propertyMap.properties.getProperties()).iterator(); |
|
847 |
property = iter.hasNext() ? iter.next() : null; |
|
848 |
skipNotEnumerable(); |
|
849 |
} |
|
850 |
||
851 |
/** |
|
852 |
* Ignore properties that are not enumerable. |
|
853 |
*/ |
|
854 |
private void skipNotEnumerable() { |
|
855 |
while (property != null && !property.isEnumerable()) { |
|
856 |
property = iter.hasNext() ? iter.next() : null; |
|
857 |
} |
|
858 |
} |
|
859 |
||
860 |
@Override |
|
861 |
public boolean hasNext() { |
|
862 |
return property != null; |
|
863 |
} |
|
864 |
||
865 |
@Override |
|
866 |
public Object next() { |
|
867 |
if (property == null) { |
|
868 |
throw new NoSuchElementException(); |
|
869 |
} |
|
870 |
||
871 |
final Object key = property.getKey(); |
|
872 |
property = iter.next(); |
|
873 |
skipNotEnumerable(); |
|
874 |
||
875 |
return key; |
|
876 |
} |
|
877 |
||
878 |
@Override |
|
879 |
public void remove() { |
|
880 |
throw new UnsupportedOperationException(); |
|
881 |
} |
|
882 |
} |
|
883 |
||
884 |
/* |
|
885 |
* Debugging and statistics. |
|
886 |
*/ |
|
887 |
||
24719 | 888 |
/** |
889 |
* Debug helper function that returns the diff of two property maps, only |
|
890 |
* displaying the information that is different and in which map it exists |
|
891 |
* compared to the other map. Can be used to e.g. debug map guards and |
|
892 |
* investigate why they fail, causing relink |
|
893 |
* |
|
894 |
* @param map0 the first property map |
|
895 |
* @param map1 the second property map |
|
896 |
* |
|
897 |
* @return property map diff as string |
|
898 |
*/ |
|
899 |
public static String diff(final PropertyMap map0, final PropertyMap map1) { |
|
900 |
final StringBuilder sb = new StringBuilder(); |
|
901 |
||
902 |
if (map0 != map1) { |
|
903 |
sb.append(">>> START: Map diff"); |
|
904 |
boolean found = false; |
|
905 |
||
906 |
for (final Property p : map0.getProperties()) { |
|
907 |
final Property p2 = map1.findProperty(p.getKey()); |
|
908 |
if (p2 == null) { |
|
909 |
sb.append("FIRST ONLY : [" + p + "]"); |
|
910 |
found = true; |
|
911 |
} else if (p2 != p) { |
|
912 |
sb.append("DIFFERENT : [" + p + "] != [" + p2 + "]"); |
|
913 |
found = true; |
|
914 |
} |
|
915 |
} |
|
916 |
||
917 |
for (final Property p2 : map1.getProperties()) { |
|
918 |
final Property p1 = map0.findProperty(p2.getKey()); |
|
919 |
if (p1 == null) { |
|
920 |
sb.append("SECOND ONLY: [" + p2 + "]"); |
|
921 |
found = true; |
|
922 |
} |
|
923 |
} |
|
924 |
||
925 |
//assert found; |
|
926 |
||
927 |
if (!found) { |
|
928 |
sb.append(map0). |
|
929 |
append("!="). |
|
930 |
append(map1); |
|
931 |
} |
|
932 |
||
933 |
sb.append("<<< END: Map diff\n"); |
|
934 |
} |
|
935 |
||
936 |
return sb.toString(); |
|
937 |
} |
|
938 |
||
16147 | 939 |
// counters updated only in debug mode |
940 |
private static int count; |
|
941 |
private static int clonedCount; |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
942 |
private static int duplicatedCount; |
16147 | 943 |
private static int historyHit; |
944 |
private static int protoInvalidations; |
|
945 |
private static int protoHistoryHit; |
|
946 |
private static int setProtoNewMapCount; |
|
947 |
||
948 |
/** |
|
949 |
* @return Total number of maps. |
|
950 |
*/ |
|
951 |
public static int getCount() { |
|
952 |
return count; |
|
953 |
} |
|
954 |
||
955 |
/** |
|
956 |
* @return The number of maps that were cloned. |
|
957 |
*/ |
|
958 |
public static int getClonedCount() { |
|
959 |
return clonedCount; |
|
960 |
} |
|
961 |
||
962 |
/** |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
963 |
* @return The number of maps that are duplicated. |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
964 |
*/ |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
965 |
public static int getDuplicatedCount() { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
966 |
return duplicatedCount; |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
967 |
} |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
968 |
|
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18852
diff
changeset
|
969 |
/** |
16147 | 970 |
* @return The number of times history was successfully used. |
971 |
*/ |
|
972 |
public static int getHistoryHit() { |
|
973 |
return historyHit; |
|
974 |
} |
|
975 |
||
976 |
/** |
|
977 |
* @return The number of times prototype changes caused invalidation. |
|
978 |
*/ |
|
979 |
public static int getProtoInvalidations() { |
|
980 |
return protoInvalidations; |
|
981 |
} |
|
982 |
||
983 |
/** |
|
984 |
* @return The number of times proto history was successfully used. |
|
985 |
*/ |
|
986 |
public static int getProtoHistoryHit() { |
|
987 |
return protoHistoryHit; |
|
988 |
} |
|
989 |
||
990 |
/** |
|
991 |
* @return The number of times prototypes were modified. |
|
992 |
*/ |
|
993 |
public static int getSetProtoNewMapCount() { |
|
994 |
return setProtoNewMapCount; |
|
995 |
} |
|
996 |
} |