Skip to content

Commit 6b39923

Browse files
authored
8294560: assertion raised in newBuiltinSwitchPoint (#18)
* Allow builtin switchpoint creation under concurrency
1 parent ab2542e commit 6b39923

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/objects/Global.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,10 +2945,7 @@ private List<org.openjdk.nashorn.internal.runtime.Property> extractBuiltinProper
29452945
* @param func builtin script object
29462946
*/
29472947
private void tagBuiltinProperties(final String name, final ScriptObject func) {
2948-
SwitchPoint sp = context.getBuiltinSwitchPoint(name);
2949-
if (sp == null) {
2950-
sp = context.newBuiltinSwitchPoint(name);
2951-
}
2948+
final SwitchPoint sp = context.getBuiltinSwitchPoint(name);
29522949

29532950
//get all builtin properties in this builtin object and register switchpoints keyed on the propery name,
29542951
//one overwrite destroys all for now, e.g. Function.prototype.apply = 17; also destroys Function.prototype.call etc

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/Context.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private static enum FieldMode {
180180
* ever needs this, given the very rare occurrence of swapping out only parts of
181181
* a builtin v.s. the entire builtin object
182182
*/
183-
private final Map<String, SwitchPoint> builtinSwitchPoints = new HashMap<>();
183+
private final Map<String, SwitchPoint> builtinSwitchPoints = new ConcurrentHashMap<>();
184184

185185
/* Force DebuggerSupport to be loaded. */
186186
static {
@@ -1729,24 +1729,13 @@ public static final class BuiltinSwitchPoint extends SwitchPoint {
17291729
}
17301730

17311731
/**
1732-
* Create a new builtin switchpoint and return it
1732+
* Return the builtin switchpoint for a particular key name. A new switchpoint
1733+
* is atomically created if it doesn't exist yet.
17331734
* @param name key name
1734-
* @return new builtin switchpoint
1735-
*/
1736-
public SwitchPoint newBuiltinSwitchPoint(final String name) {
1737-
assert builtinSwitchPoints.get(name) == null;
1738-
final SwitchPoint sp = new BuiltinSwitchPoint();
1739-
builtinSwitchPoints.put(name, sp);
1740-
return sp;
1741-
}
1742-
1743-
/**
1744-
* Return the builtin switchpoint for a particular key name
1745-
* @param name key name
1746-
* @return builtin switchpoint or null if none
1735+
* @return builtin switchpoint
17471736
*/
17481737
public SwitchPoint getBuiltinSwitchPoint(final String name) {
1749-
return builtinSwitchPoints.get(name);
1738+
return builtinSwitchPoints.computeIfAbsent(name, n -> new BuiltinSwitchPoint());
17501739
}
17511740

17521741
private static ClassLoader createModuleLoader(final ClassLoader cl,

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/ScriptRuntime.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,6 @@ public static boolean GE(final Object x, final Object y) {
11611161
public static void invalidateReservedBuiltinName(final String name) {
11621162
final Context context = Context.getContextTrusted();
11631163
final SwitchPoint sp = context.getBuiltinSwitchPoint(name);
1164-
assert sp != null;
11651164
context.getLogger(ApplySpecialization.class).info("Overwrote special name '" + name +"' - invalidating switchpoint");
11661165
SwitchPoint.invalidateAll(new SwitchPoint[] { sp });
11671166
}

0 commit comments

Comments
 (0)