Skip to content

Commit

Permalink
[GR-16446] Make all Specializations protected.
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/980
  • Loading branch information
pitr-ch committed Aug 18, 2019
2 parents 160907d + e0c0a63 commit 5458f47
Show file tree
Hide file tree
Showing 252 changed files with 2,499 additions and 2,481 deletions.
18 changes: 17 additions & 1 deletion src/main/java/org/truffleruby/builtins/LowerFixnumChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.truffleruby.RubyLanguage;
import org.truffleruby.SuppressFBWarnings;
Expand All @@ -27,10 +30,23 @@ public class LowerFixnumChecker {
public static boolean SUCCESS = true;

@SuppressFBWarnings("Dm")
@SuppressWarnings("unchecked")
public static void checkLowerFixnumArguments(NodeFactory<? extends RubyNode> nodeFactory, int initialSkip, int[] lowerFixnum) {
final Class<? extends RubyNode> nodeClass = nodeFactory.getNodeClass();
byte[] lowerArgs = null;
for (Method specialization : nodeClass.getDeclaredMethods()) {

List<Method> methods = new ArrayList<>();
Class<? extends RubyNode> nodeClassIt = nodeClass;
while (true) {
methods.addAll(Arrays.asList(nodeClassIt.getDeclaredMethods()));

nodeClassIt = (Class<? extends RubyNode>) nodeClassIt.getSuperclass();
if (nodeClassIt == RubyNode.class) {
break;
}
}

for (Method specialization : methods) {
if (specialization.isAnnotationPresent(Specialization.class)) {
Class<?>[] argumentTypes = specialization.getParameterTypes();
int skip = initialSkip;
Expand Down
160 changes: 80 additions & 80 deletions src/main/java/org/truffleruby/cext/CExtNodes.java

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/main/java/org/truffleruby/cext/UnwrapNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ public static abstract class UnwrapNativeNode extends RubyBaseNode {
public abstract Object execute(long handle);

@Specialization(guards = "handle == FALSE_HANDLE")
public boolean unwrapFalse(long handle) {
protected boolean unwrapFalse(long handle) {
return false;
}

@Specialization(guards = "handle == TRUE_HANDLE")
public boolean unwrapTrue(long handle) {
protected boolean unwrapTrue(long handle) {
return true;
}

@Specialization(guards = "handle == UNDEF_HANDLE")
public NotProvided unwrapUndef(long handle) {
protected NotProvided unwrapUndef(long handle) {
return NotProvided.INSTANCE;
}

@Specialization(guards = "handle == NIL_HANDLE")
public DynamicObject unwrapNil(long handle) {
protected DynamicObject unwrapNil(long handle) {
return nil();
}

@Specialization(guards = "isTaggedLong(handle)")
public long unwrapTaggedLong(long handle) {
protected long unwrapTaggedLong(long handle) {
return handle >> 1;
}

@Specialization(guards = "isTaggedObject(handle)")
public Object unwrapTaggedObject(long handle) {
protected Object unwrapTaggedObject(long handle) {
return getContext().getValueWrapperManager().getFromHandleMap(handle);
}

Expand All @@ -92,32 +92,32 @@ public static abstract class NativeToWrapperNode extends RubyBaseNode {
public abstract ValueWrapper execute(long handle);

@Specialization(guards = "handle == FALSE_HANDLE")
public ValueWrapper unwrapFalse(long handle) {
protected ValueWrapper unwrapFalse(long handle) {
return new ValueWrapper(false, FALSE_HANDLE);
}

@Specialization(guards = "handle == TRUE_HANDLE")
public ValueWrapper unwrapTrue(long handle) {
protected ValueWrapper unwrapTrue(long handle) {
return new ValueWrapper(true, TRUE_HANDLE);
}

@Specialization(guards = "handle == UNDEF_HANDLE")
public ValueWrapper unwrapUndef(long handle) {
protected ValueWrapper unwrapUndef(long handle) {
return new ValueWrapper(NotProvided.INSTANCE, UNDEF_HANDLE);
}

@Specialization(guards = "handle == NIL_HANDLE")
public ValueWrapper unwrapNil(long handle) {
protected ValueWrapper unwrapNil(long handle) {
return new ValueWrapper(nil(), NIL_HANDLE);
}

@Specialization(guards = "isTaggedLong(handle)")
public ValueWrapper unwrapTaggedLong(long handle) {
protected ValueWrapper unwrapTaggedLong(long handle) {
return new ValueWrapper(handle >> 1, handle);
}

@Specialization(guards = "isTaggedObject(handle)")
public ValueWrapper unwrapTaggedObject(long handle) {
protected ValueWrapper unwrapTaggedObject(long handle) {
return getContext().getValueWrapperManager().getWrapperFromHandleMap(handle);
}

Expand All @@ -139,12 +139,12 @@ public static abstract class ToWrapperNode extends RubyBaseNode {
public abstract ValueWrapper execute(TruffleObject value);

@Specialization
public ValueWrapper wrappedValueWrapper(ValueWrapper value) {
protected ValueWrapper wrappedValueWrapper(ValueWrapper value) {
return value;
}

@Specialization(guards = "!isWrapper(value)", limit = "getCacheLimit()")
public ValueWrapper unwrapTypeCastObject(TruffleObject value,
protected ValueWrapper unwrapTypeCastObject(TruffleObject value,
@CachedLibrary("value") InteropLibrary values,
@Cached NativeToWrapperNode nativeToWrapperNode,
@Cached BranchProfile unsupportedProfile,
Expand Down Expand Up @@ -176,12 +176,12 @@ protected int getCacheLimit() {
public abstract Object execute(TruffleObject value);

@Specialization
public Object unwrapValue(ValueWrapper value) {
protected Object unwrapValue(ValueWrapper value) {
return value.getObject();
}

@Specialization(guards = "!isWrapper(value)", limit = "getCacheLimit()")
public Object unwrapTypeCastObject(TruffleObject value,
protected Object unwrapTypeCastObject(TruffleObject value,
@CachedLibrary("value") InteropLibrary values,
@Cached UnwrapNativeNode unwrapNativeNode,
@Cached BranchProfile unsupportedProfile,
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/truffleruby/cext/WrapNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static WrapNode create() {
public abstract ValueWrapper execute(Object value);

@Specialization
public ValueWrapper wrapLong(long value,
protected ValueWrapper wrapLong(long value,
@Cached BranchProfile smallFixnumProfile,
@CachedContext(RubyLanguage.class) RubyContext context) {
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
Expand All @@ -59,35 +59,35 @@ public ValueWrapper wrapLong(long value,
}

@Specialization
public ValueWrapper wrapDouble(double value,
protected ValueWrapper wrapDouble(double value,
@CachedContext(RubyLanguage.class) RubyContext context) {
return context.getValueWrapperManager().doubleWrapper(value);
}

@Specialization
public ValueWrapper wrapBoolean(boolean value) {
protected ValueWrapper wrapBoolean(boolean value) {
return new ValueWrapper(value, value ? TRUE_HANDLE : FALSE_HANDLE);
}

@Specialization
public ValueWrapper wrapUndef(NotProvided value) {
protected ValueWrapper wrapUndef(NotProvided value) {
return new ValueWrapper(value, UNDEF_HANDLE);
}

@Specialization
public ValueWrapper wrapWrappedValue(ValueWrapper value,
protected ValueWrapper wrapWrappedValue(ValueWrapper value,
@CachedContext(RubyLanguage.class) RubyContext context) {
throw new RaiseException(context, context.getCoreExceptions().argumentError(RopeOperations.encodeAscii("Wrapping wrapped object", UTF8Encoding.INSTANCE), this));
}

@Specialization(guards = "isNil(context, value)")
public ValueWrapper wrapNil(DynamicObject value,
protected ValueWrapper wrapNil(DynamicObject value,
@CachedContext(RubyLanguage.class) RubyContext context) {
return new ValueWrapper(context.getCoreLibrary().getNil(), NIL_HANDLE);
}

@Specialization(guards = { "isRubyBasicObject(value)", "!isNil(context, value)" })
public ValueWrapper wrapValue(DynamicObject value,
protected ValueWrapper wrapValue(DynamicObject value,
@Cached ReadObjectFieldNode readWrapperNode,
@Cached WriteObjectFieldNode writeWrapperNode,
@Cached BranchProfile noHandleProfile,
Expand All @@ -112,7 +112,7 @@ public ValueWrapper wrapValue(DynamicObject value,
}

@Specialization(guards = "!isRubyBasicObject(value)")
public ValueWrapper wrapNonRubyObject(TruffleObject value,
protected ValueWrapper wrapNonRubyObject(TruffleObject value,
@CachedContext(RubyLanguage.class) RubyContext context) {
throw new RaiseException(context, context.getCoreExceptions().argumentError("Attempt to wrap something that isn't an Ruby object", this));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/truffleruby/core/GCNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract static class CountNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization
public int count() {
protected int count() {
return getCollectionCount();
}

Expand All @@ -46,7 +46,7 @@ public abstract static class TimeNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization
public long time() {
protected long time() {
return getCollectionTime();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/truffleruby/core/MainNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract static class PublicNode extends CoreMethodArrayArgumentsNode {
@Child private ModuleNodes.PublicNode publicNode = ModuleNodesFactory.PublicNodeFactory.create(null);

@Specialization
public DynamicObject doPublic(VirtualFrame frame, Object[] args) {
protected DynamicObject doPublic(VirtualFrame frame, Object[] args) {
final DynamicObject object = coreLibrary().getObjectClass();
return publicNode.executePublic(frame, object, args);
}
Expand All @@ -50,7 +50,7 @@ public abstract static class PrivateNode extends CoreMethodArrayArgumentsNode {
@Child private ModuleNodes.PrivateNode privateNode = ModuleNodesFactory.PrivateNodeFactory.create(null);

@Specialization
public DynamicObject doPrivate(VirtualFrame frame, Object[] args) {
protected DynamicObject doPrivate(VirtualFrame frame, Object[] args) {
final DynamicObject object = coreLibrary().getObjectClass();
return privateNode.executePrivate(frame, object, args);
}
Expand All @@ -62,7 +62,7 @@ public abstract static class MainUsingNode extends CoreMethodArrayArgumentsNode
@Child private UsingNode usingNode = UsingNodeGen.create();

@Specialization(guards = "isRubyModule(refinementModule)")
public DynamicObject mainUsing(DynamicObject refinementModule,
protected DynamicObject mainUsing(DynamicObject refinementModule,
@Cached BranchProfile errorProfile) {
if (!isCalledFromTopLevel()) {
errorProfile.enter();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/truffleruby/core/MarkingServiceNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static abstract class KeepAliveNode extends RubyBaseWithoutContextNode {
public abstract void execute(Object object);

@Specialization
public void keepObjectAlive(Object object,
protected void keepObjectAlive(Object object,
@Cached GetMarkerThreadLocalDataNode getThreadLocalDataNode) {
MarkerThreadLocalData data = getThreadLocalDataNode.execute();
addToList(data.getExtensionCallStack().getKeptObjects(), object);
Expand All @@ -57,7 +57,7 @@ public final MarkerThreadLocalData execute() {
public abstract MarkerThreadLocalData execute(Object dynamicParameter);

@Specialization(guards = "thread == currentJavaThread(dynamicParameter)", limit = "getCacheLimit()")
public MarkerThreadLocalData getDataOnKnownThread(
protected MarkerThreadLocalData getDataOnKnownThread(
Object dynamicParameter,
@CachedContext(RubyLanguage.class) RubyContext context,
@Cached("currentJavaThread(dynamicParameter)") Thread thread,
Expand Down
Loading

0 comments on commit 5458f47

Please sign in to comment.