Skip to content

Commit

Permalink
8294560: assertion raised in newBuiltinSwitchPoint (#18)
Browse files Browse the repository at this point in the history
* Allow builtin switchpoint creation under concurrency
  • Loading branch information
szegedi committed Feb 7, 2023
1 parent ab2542e commit 6b39923
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2945,10 +2945,7 @@ private List<org.openjdk.nashorn.internal.runtime.Property> extractBuiltinProper
* @param func builtin script object
*/
private void tagBuiltinProperties(final String name, final ScriptObject func) {
SwitchPoint sp = context.getBuiltinSwitchPoint(name);
if (sp == null) {
sp = context.newBuiltinSwitchPoint(name);
}
final SwitchPoint sp = context.getBuiltinSwitchPoint(name);

//get all builtin properties in this builtin object and register switchpoints keyed on the propery name,
//one overwrite destroys all for now, e.g. Function.prototype.apply = 17; also destroys Function.prototype.call etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static enum FieldMode {
* ever needs this, given the very rare occurrence of swapping out only parts of
* a builtin v.s. the entire builtin object
*/
private final Map<String, SwitchPoint> builtinSwitchPoints = new HashMap<>();
private final Map<String, SwitchPoint> builtinSwitchPoints = new ConcurrentHashMap<>();

/* Force DebuggerSupport to be loaded. */
static {
Expand Down Expand Up @@ -1729,24 +1729,13 @@ public static final class BuiltinSwitchPoint extends SwitchPoint {
}

/**
* Create a new builtin switchpoint and return it
* Return the builtin switchpoint for a particular key name. A new switchpoint
* is atomically created if it doesn't exist yet.
* @param name key name
* @return new builtin switchpoint
*/
public SwitchPoint newBuiltinSwitchPoint(final String name) {
assert builtinSwitchPoints.get(name) == null;
final SwitchPoint sp = new BuiltinSwitchPoint();
builtinSwitchPoints.put(name, sp);
return sp;
}

/**
* Return the builtin switchpoint for a particular key name
* @param name key name
* @return builtin switchpoint or null if none
* @return builtin switchpoint
*/
public SwitchPoint getBuiltinSwitchPoint(final String name) {
return builtinSwitchPoints.get(name);
return builtinSwitchPoints.computeIfAbsent(name, n -> new BuiltinSwitchPoint());
}

private static ClassLoader createModuleLoader(final ClassLoader cl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ public static boolean GE(final Object x, final Object y) {
public static void invalidateReservedBuiltinName(final String name) {
final Context context = Context.getContextTrusted();
final SwitchPoint sp = context.getBuiltinSwitchPoint(name);
assert sp != null;
context.getLogger(ApplySpecialization.class).info("Overwrote special name '" + name +"' - invalidating switchpoint");
SwitchPoint.invalidateAll(new SwitchPoint[] { sp });
}
Expand Down

0 comments on commit 6b39923

Please sign in to comment.