author | hannesw |
Wed, 21 Mar 2018 16:55:34 +0100 | |
changeset 49275 | c639a6b33c5c |
parent 47713 | 530f16bacbfd |
permissions | -rw-r--r-- |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
1 |
/* |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
4 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
10 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
15 |
* accompanied this code). |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
16 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
20 |
* |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
23 |
* questions. |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
24 |
*/ |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
25 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
26 |
package jdk.nashorn.internal.runtime; |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
27 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
28 |
import java.lang.invoke.SwitchPoint; |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
29 |
import java.util.Collections; |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
30 |
import java.util.HashMap; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
31 |
import java.util.Map; |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
32 |
import java.util.Set; |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
33 |
import java.util.WeakHashMap; |
32527
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
34 |
import java.util.concurrent.atomic.LongAdder; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
35 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
36 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
37 |
* Helper class for tracking and invalidation of switchpoints for inherited properties. |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
38 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
39 |
public class PropertySwitchPoints { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
40 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
41 |
private final Map<Object, WeakSwitchPointSet> switchPointMap = new HashMap<>(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
42 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
43 |
private final static SwitchPoint[] EMPTY_SWITCHPOINT_ARRAY = new SwitchPoint[0]; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
44 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
45 |
// These counters are updated in debug mode |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
46 |
private static LongAdder switchPointsAdded; |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
47 |
private static LongAdder switchPointsInvalidated; |
32527
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
48 |
|
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
49 |
static { |
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
50 |
if (Context.DEBUG) { |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
51 |
switchPointsAdded = new LongAdder(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
52 |
switchPointsInvalidated = new LongAdder(); |
32527
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
53 |
} |
b105632002c5
8027137: Merge ScriptFunction and ScriptFunctionImpl
sundar
parents:
25865
diff
changeset
|
54 |
} |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
55 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
56 |
/** |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
57 |
* Copy constructor |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
58 |
* |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
59 |
* @param switchPoints Proto switchpoints to copy |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
60 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
61 |
private PropertySwitchPoints(final PropertySwitchPoints switchPoints) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
62 |
if (switchPoints != null) { |
35322
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
63 |
// We need to copy the nested weak sets in order to avoid concurrent modification issues, see JDK-8146274 |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
64 |
synchronized (switchPoints) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
65 |
for (final Map.Entry<Object, WeakSwitchPointSet> entry : switchPoints.switchPointMap.entrySet()) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
66 |
this.switchPointMap.put(entry.getKey(), new WeakSwitchPointSet(entry.getValue())); |
35322
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
67 |
} |
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
68 |
} |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
69 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
70 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
71 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
72 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
73 |
* Return aggregate switchpoints added to all ProtoSwitchPoints |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
74 |
* @return the number of switchpoints added |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
75 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
76 |
public static long getSwitchPointsAdded() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
77 |
return switchPointsAdded.longValue(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
78 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
79 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
80 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
81 |
* Return aggregate switchPointMap invalidated in all ProtoSwitchPoints |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
82 |
* @return the number of switchpoints invalidated |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
83 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
84 |
public static long getSwitchPointsInvalidated() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
85 |
return switchPointsInvalidated.longValue(); |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32527
diff
changeset
|
86 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32527
diff
changeset
|
87 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32527
diff
changeset
|
88 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
89 |
* Return number of property switchPoints added to a ScriptObject. |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
90 |
* @param obj the object |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
91 |
* @return the switchpoint count |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
32527
diff
changeset
|
92 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
93 |
public static int getSwitchPointCount(final ScriptObject obj) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
94 |
return obj.getMap().getSwitchPointCount(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
95 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
96 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
97 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
98 |
* Return the number of switchpoints added to this ProtoSwitchPoints instance. |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
99 |
* @return the switchpoint count; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
100 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
101 |
int getSwitchPointCount() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
102 |
return switchPointMap.size(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
103 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
104 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
105 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
106 |
* Add {@code switchPoint} to the switchpoints for for property {@code key}, creating |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
107 |
* and returning a new {@code ProtoSwitchPoints} instance if the switchpoint was not already contained |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
108 |
* |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
109 |
* @param oldSwitchPoints the original PropertySwitchPoints instance. May be null |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
110 |
* @param key the property key |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
111 |
* @param switchPoint the switchpoint to be added |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
112 |
* @return the new PropertySwitchPoints instance, or this instance if switchpoint was already contained |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
113 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
114 |
static PropertySwitchPoints addSwitchPoint(final PropertySwitchPoints oldSwitchPoints, final String key, final SwitchPoint switchPoint) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
115 |
if (oldSwitchPoints == null || !oldSwitchPoints.contains(key, switchPoint)) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
116 |
final PropertySwitchPoints newSwitchPoints = new PropertySwitchPoints(oldSwitchPoints); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
117 |
newSwitchPoints.add(key, switchPoint); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
118 |
return newSwitchPoints; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
119 |
} |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
120 |
return oldSwitchPoints; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
121 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
122 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
123 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
124 |
* Checks whether {@code switchPoint} is contained in {@code key}'s set. |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
125 |
* |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
126 |
* @param key the property key |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
127 |
* @param switchPoint the switchPoint |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
128 |
* @return true if switchpoint is already contained for key |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
129 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
130 |
private synchronized boolean contains(final String key, final SwitchPoint switchPoint) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
131 |
final WeakSwitchPointSet set = this.switchPointMap.get(key); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
132 |
return set != null && set.contains(switchPoint); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
133 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
134 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
135 |
private synchronized void add(final String key, final SwitchPoint switchPoint) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
136 |
if (Context.DEBUG) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
137 |
switchPointsAdded.increment(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
138 |
} |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
139 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
140 |
WeakSwitchPointSet set = this.switchPointMap.get(key); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
141 |
if (set == null) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
142 |
set = new WeakSwitchPointSet(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
143 |
this.switchPointMap.put(key, set); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
144 |
} |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
145 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
146 |
set.add(switchPoint); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
147 |
} |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
148 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
149 |
Set<SwitchPoint> getSwitchPoints(final Object key) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
150 |
WeakSwitchPointSet switchPointSet = switchPointMap.get(key); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
151 |
if (switchPointSet != null) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
152 |
return switchPointSet.elements(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
153 |
} |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
154 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
155 |
return Collections.emptySet(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
156 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
157 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
158 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
159 |
* Invalidate all switchpoints for the given property. This is called when that |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
160 |
* property is created, deleted, or modified in a script object. |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
161 |
* |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
162 |
* @param prop The property to invalidate. |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
163 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
164 |
synchronized void invalidateProperty(final Property prop) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
165 |
final WeakSwitchPointSet set = switchPointMap.get(prop.getKey()); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
166 |
if (set != null) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
167 |
if (Context.DEBUG) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
168 |
switchPointsInvalidated.add(set.size()); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
169 |
} |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
170 |
final SwitchPoint[] switchPoints = set.elements().toArray(EMPTY_SWITCHPOINT_ARRAY); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
171 |
SwitchPoint.invalidateAll(switchPoints); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
172 |
this.switchPointMap.remove(prop.getKey()); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
173 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
174 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
175 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
176 |
|
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
23084
diff
changeset
|
177 |
/** |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
178 |
* Invalidate all switchpoints except those defined in {@code map}. This is called |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
179 |
* when the prototype of a script object is changed. |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
180 |
* |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
181 |
* @param map map of properties to exclude from invalidation |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
23084
diff
changeset
|
182 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
183 |
synchronized void invalidateInheritedProperties(final PropertyMap map) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
184 |
for (final Map.Entry<Object, WeakSwitchPointSet> entry : switchPointMap.entrySet()) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
185 |
if (map.findProperty(entry.getKey()) != null) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
186 |
continue; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
187 |
} |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
188 |
if (Context.DEBUG) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
189 |
switchPointsInvalidated.add(entry.getValue().size()); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
190 |
} |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
191 |
final SwitchPoint[] switchPoints = entry.getValue().elements().toArray(EMPTY_SWITCHPOINT_ARRAY); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
192 |
SwitchPoint.invalidateAll(switchPoints); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
193 |
} |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
194 |
switchPointMap.clear(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
195 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
196 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
197 |
private static class WeakSwitchPointSet { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
198 |
|
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
199 |
private final WeakHashMap<SwitchPoint, Void> map; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
200 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
201 |
WeakSwitchPointSet() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
202 |
map = new WeakHashMap<>(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
203 |
} |
35322
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
204 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
205 |
WeakSwitchPointSet(final WeakSwitchPointSet set) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
206 |
map = new WeakHashMap<>(set.map); |
35322
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
207 |
} |
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
208 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
209 |
void add(final SwitchPoint switchPoint) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
210 |
map.put(switchPoint, null); |
35322
eff26d265a9d
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
hannesw
parents:
33690
diff
changeset
|
211 |
} |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
212 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
213 |
boolean contains(final SwitchPoint switchPoint) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
214 |
return map.containsKey(switchPoint); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
215 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
216 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
217 |
Set<SwitchPoint> elements() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
218 |
return map.keySet(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
219 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
220 |
|
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
221 |
int size() { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
222 |
return map.size(); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
223 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
224 |
|
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
225 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
diff
changeset
|
226 |
} |