Skip to content
Snippets Groups Projects
Commit cfb80ade authored by stepan's avatar stepan
Browse files

ListBuiltin and Quote: make share permanent only when cached.

Plus: assertions in RSharingAttributeStorage and removed unnecessary code from WriteIndexedVectorNode.
parent fe0c5f9f
Branches
No related tags found
No related merge requests found
......@@ -53,7 +53,19 @@ public abstract class ListBuiltin extends RBuiltinNode {
@CompilationFinal private RStringVector suppliedSignatureArgNames;
protected RStringVector argNameVector(ArgumentsSignature signature) {
/**
* Creates a shared permanent vector so that it can be re-used for every list(...) with the same
* arguments
*/
protected final RStringVector cachedArgNameVector(ArgumentsSignature signature) {
RStringVector result = argNameVector(signature);
if (result != null) {
result.makeSharedPermanent();
}
return result;
}
protected final RStringVector argNameVector(ArgumentsSignature signature) {
if (namesNull.profile(signature.getNonNullCount() == 0)) {
return null;
}
......@@ -63,9 +75,6 @@ public abstract class ListBuiltin extends RBuiltinNode {
names[i] = (orgName == null ? RRuntime.NAMES_ATTR_EMPTY_VALUE : orgName);
}
RStringVector result = RDataFactory.createStringVector(names, RDataFactory.COMPLETE_VECTOR);
// this is going to be a cached vector re-used for every list(...) with the same arguments,
// it has to be shared.
result.makeSharedPermanent();
return result;
}
......@@ -81,7 +90,7 @@ public abstract class ListBuiltin extends RBuiltinNode {
protected RList listCached(RArgsValuesAndNames args, //
@Cached("args.getLength()") int cachedLength, //
@SuppressWarnings("unused") @Cached("args.getSignature()") ArgumentsSignature cachedSignature, //
@Cached("argNameVector(cachedSignature)") RStringVector cachedArgNames) {
@Cached("cachedArgNameVector(cachedSignature)") RStringVector cachedArgNames) {
Object[] argArray = args.getArguments();
for (int i = 0; i < cachedLength; i++) {
getShareObjectNode(i).execute(argArray[i]);
......
......@@ -44,19 +44,27 @@ public abstract class Quote extends RBuiltinNode {
public abstract Object execute(RPromise expr);
protected final Object createLanguage(Closure closure) {
Object o = RASTUtils.createLanguageElement(closure.getExpr().asRSyntaxNode());
if (shareableProfile.profile(o instanceof RShareable)) {
((RShareable) o).makeSharedPermanent();
/**
* Creates a shared permanent language so that it can be cached and repeatedly returned as the
* result.
*/
protected final Object cachedCreateLanguage(Closure closure) {
Object result = createLanguage(closure);
if (shareableProfile.profile(result instanceof RShareable)) {
((RShareable) result).makeSharedPermanent();
}
return o;
return result;
}
protected final Object createLanguage(Closure closure) {
return RASTUtils.createLanguageElement(closure.getExpr().asRSyntaxNode());
}
@SuppressWarnings("unused")
@Specialization(limit = "LIMIT", guards = "cachedClosure == expr.getClosure()")
protected Object quoteCached(RPromise expr,
@Cached("expr.getClosure()") Closure cachedClosure,
@Cached("createLanguage(cachedClosure)") Object language) {
@Cached("cachedCreateLanguage(cachedClosure)") Object language) {
return language;
}
......
......@@ -473,7 +473,6 @@ abstract class WriteIndexedVectorNode extends Node {
private final boolean setListElementAsObject;
private final boolean isReplace;
private final ConditionProfile isShareable = ConditionProfile.createBinaryProfile();
@Child private UpdateStateOfListElement updateStateOfListElement;
@Child private ShareObjectNode shareObjectNode;
......@@ -481,9 +480,9 @@ abstract class WriteIndexedVectorNode extends Node {
this.setListElementAsObject = setListElementAsObject;
this.isReplace = isReplace;
if (!isReplace) {
updateStateOfListElement = insert(UpdateStateOfListElement.create());
updateStateOfListElement = UpdateStateOfListElement.create();
} else {
shareObjectNode = insert(ShareObjectNode.create());
shareObjectNode = ShareObjectNode.create();
}
}
......
......@@ -47,7 +47,8 @@ public abstract class RSharingAttributeStorage extends RAttributeStorage impleme
@Override
public final void decRefCount() {
assert refCount > 0;
assert refCount != SHARED_PERMANENT_VAL : "cannot decRefCount of shared permanent value";
assert refCount > 0 : "cannot decRefCount when refCount <= 0";
refCount--;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment