Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5078c4053868
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a663c1ac083
Choose a head ref
  • 13 commits
  • 13 files changed
  • 1 contributor

Commits on May 18, 2016

  1. Copy the full SHA
    db39ee7 View commit details
  2. Copy the full SHA
    ed1988d View commit details
  3. [Truffle] Formatting

    pitr-ch committed May 18, 2016
    Copy the full SHA
    aa637cc View commit details
  4. Copy the full SHA
    6ceff1c View commit details
  5. Copy the full SHA
    0b88148 View commit details
  6. [Truffle] Formatting

    pitr-ch committed May 18, 2016
    Copy the full SHA
    0fc21ee View commit details
  7. Copy the full SHA
    899bc6f View commit details
  8. Copy the full SHA
    0dfee5f View commit details
  9. Copy the full SHA
    3b4fe3e View commit details
  10. [Truffle] Formatting

    pitr-ch committed May 18, 2016
    Copy the full SHA
    143b725 View commit details
  11. Copy the full SHA
    98d92fc View commit details
  12. Copy the full SHA
    10aa949 View commit details
  13. [Truffle] Use cached value instead of argument value in guards

    when referential equality of the argument value and its cached value is guarded
    pitr-ch committed May 18, 2016
    Copy the full SHA
    6a663c1 View commit details
Original file line number Diff line number Diff line change
@@ -924,8 +924,8 @@ public abstract static class InitializeNode extends YieldingCoreMethodNode {
@Child private ToIntNode toIntNode;
@Child private CallDispatchHeadNode toAryNode;
@Child private KernelNodes.RespondToNode respondToToAryNode;
public abstract DynamicObject executeInitialize(VirtualFrame frame, DynamicObject array, Object size, Object value, Object block);

public abstract DynamicObject executeInitialize(VirtualFrame frame, DynamicObject array, Object size, Object defaultValue, Object block);

@Specialization
public DynamicObject initializeNoArgs(DynamicObject array, NotProvided size, NotProvided unusedValue, NotProvided block) {
Original file line number Diff line number Diff line change
@@ -971,7 +971,7 @@ public RubyNode coerceToSymbolOrString(RubyNode name) {
}

@Specialization(
guards = { "isRubySymbol(name)", "name == cachedName" },
guards = { "name == cachedName" , "isRubySymbol(cachedName)" },
limit = "getCacheLimit()")
public Object instanceVariableGetSymbolCached(DynamicObject object, DynamicObject name,
@Cached("name") DynamicObject cachedName,
@@ -1027,7 +1027,7 @@ public RubyNode coerceToSymbolOrString(RubyNode name) {
}

@Specialization(
guards = { "isRubySymbol(name)", "name == cachedName" },
guards = { "name == cachedName", "isRubySymbol(cachedName)" },
limit = "getCacheLimit()")
public Object instanceVariableSetSymbolCached(DynamicObject object, DynamicObject name, Object value,
@Cached("name") DynamicObject cachedName,
Original file line number Diff line number Diff line change
@@ -97,10 +97,19 @@ public ModuleFields(RubyContext context, DynamicObject lexicalParent, String giv
start = new PrependMarker(this);
}

public void getAdoptedByLexicalParent(RubyContext context, DynamicObject lexicalParent, String name, Node currentNode) {
public void getAdoptedByLexicalParent(
RubyContext context,
DynamicObject lexicalParent,
String name,
Node currentNode) {
assert RubyGuards.isRubyModule(lexicalParent);

Layouts.MODULE.getFields(lexicalParent).setConstantInternal(context, currentNode, name, rubyModuleObject, false);
Layouts.MODULE.getFields(lexicalParent).setConstantInternal(
context,
currentNode,
name,
rubyModuleObject,
false);
Layouts.MODULE.getFields(lexicalParent).addLexicalDependent(rubyModuleObject);

if (!hasFullName()) {
@@ -126,7 +135,11 @@ public void updateAnonymousChildrenModules(RubyContext context) {
if (RubyGuards.isRubyModule(constant.getValue())) {
DynamicObject module = (DynamicObject) constant.getValue();
if (!Layouts.MODULE.getFields(module).hasFullName()) {
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(context, rubyModuleObject, entry.getKey(), null);
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(
context,
rubyModuleObject,
entry.getKey(),
null);
}
}
}
@@ -322,9 +335,17 @@ public void addMethod(RubyContext context, Node currentNode, InternalMethod meth
if (context.getCoreLibrary().isLoaded() && !method.isUndefined()) {
if (Layouts.CLASS.isClass(rubyModuleObject) && Layouts.CLASS.getIsSingleton(rubyModuleObject)) {
DynamicObject receiver = Layouts.CLASS.getAttached(rubyModuleObject);
context.send(receiver, "singleton_method_added", null, context.getSymbolTable().getSymbol(method.getName()));
context.send(
receiver,
"singleton_method_added",
null,
context.getSymbolTable().getSymbol(method.getName()));
} else {
context.send(rubyModuleObject, "method_added", null, context.getSymbolTable().getSymbol(method.getName()));
context.send(
rubyModuleObject,
"method_added",
null,
context.getSymbolTable().getSymbol(method.getName()));
}
}
}
@@ -339,7 +360,10 @@ public void removeMethod(String methodName) {
public void undefMethod(RubyContext context, Node currentNode, String methodName) {
final InternalMethod method = ModuleOperations.lookupMethod(rubyModuleObject, methodName);
if (method == null) {
throw new RaiseException(context.getCoreExceptions().nameErrorUndefinedMethod(methodName, rubyModuleObject, currentNode));
throw new RaiseException(context.getCoreExceptions().nameErrorUndefinedMethod(
methodName,
rubyModuleObject,
currentNode));
} else {
addMethod(context, currentNode, method.undefined());
}
@@ -374,7 +398,10 @@ public void alias(RubyContext context, Node currentNode, String newName, String

if (method == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreExceptions().nameErrorUndefinedMethod(oldName, rubyModuleObject, currentNode));
throw new RaiseException(context.getCoreExceptions().nameErrorUndefinedMethod(
oldName,
rubyModuleObject,
currentNode));
}

InternalMethod aliasMethod = method.withName(newName);
@@ -387,8 +414,11 @@ public void alias(RubyContext context, Node currentNode, String newName, String
}

@TruffleBoundary
public void changeConstantVisibility(RubyContext context, Node currentNode, String name, boolean isPrivate) {
checkFrozen(context, currentNode);
public void changeConstantVisibility(
final RubyContext context,
final Node currentNode,
final String name,
final boolean isPrivate) {

while (true) {
final RubyConstant previous = constants.get(name);
@@ -569,7 +599,10 @@ public Collection<DynamicObject> filterMethods(RubyContext context, boolean incl
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterMethodsOnObject(RubyContext context, boolean includeAncestors, MethodFilter filter) {
public Collection<DynamicObject> filterMethodsOnObject(
RubyContext context,
boolean includeAncestors,
MethodFilter filter) {
final Map<String, InternalMethod> allMethods;
if (includeAncestors) {
allMethods = ModuleOperations.getAllMethods(rubyModuleObject);
@@ -579,7 +612,10 @@ public Collection<DynamicObject> filterMethodsOnObject(RubyContext context, bool
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterSingletonMethods(RubyContext context, boolean includeAncestors, MethodFilter filter) {
public Collection<DynamicObject> filterSingletonMethods(
RubyContext context,
boolean includeAncestors,
MethodFilter filter) {
final Map<String, InternalMethod> allMethods;
if (includeAncestors) {
allMethods = ModuleOperations.getMethodsBeforeLogicalClass(rubyModuleObject);
@@ -589,7 +625,10 @@ public Collection<DynamicObject> filterSingletonMethods(RubyContext context, boo
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterMethods(RubyContext context, Map<String, InternalMethod> allMethods, MethodFilter filter) {
public Collection<DynamicObject> filterMethods(
RubyContext context,
Map<String, InternalMethod> allMethods,
MethodFilter filter) {
final Map<String, InternalMethod> methods = ModuleOperations.withoutUndefinedMethods(allMethods);

final Set<DynamicObject> filtered = new HashSet<>();
45 changes: 36 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/core/range/RangeNodes.java
Original file line number Diff line number Diff line change
@@ -48,12 +48,14 @@ public abstract class RangeNodes {
public abstract static class MapNode extends YieldingCoreMethodNode {

@Specialization(guards = "isIntegerFixnumRange(range)")
public DynamicObject map(VirtualFrame frame, DynamicObject range, DynamicObject block,
public DynamicObject map(
VirtualFrame frame, DynamicObject range, DynamicObject block,
@Cached("create(getContext())") ArrayBuilderNode arrayBuilder) {
final int begin = Layouts.INTEGER_FIXNUM_RANGE.getBegin(range);
final int end = Layouts.INTEGER_FIXNUM_RANGE.getEnd(range);
final boolean excludedEnd = Layouts.INTEGER_FIXNUM_RANGE.getExcludedEnd(range);
final int length = (excludedEnd ? end : end + 1) - begin;
final int direction = begin < end ? +1 : -1;
final int length = Math.abs((excludedEnd ? end : end + direction) - begin);

Object store = arrayBuilder.start(length);
int count = 0;
@@ -64,15 +66,18 @@ public DynamicObject map(VirtualFrame frame, DynamicObject range, DynamicObject
count++;
}

store = arrayBuilder.appendValue(store, n, yield(frame, block, begin + n));
store = arrayBuilder.appendValue(store, n, yield(frame, block, begin + direction * n));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
LoopNode.reportLoopCount(this, count);
}
}

return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), arrayBuilder.finish(store, length), length);
return Layouts.ARRAY.createArray(
coreLibrary().getArrayFactory(),
arrayBuilder.finish(store, length),
length);
}

}
@@ -358,7 +363,12 @@ public Object stepInt(VirtualFrame frame, DynamicObject range, NotProvided step,
return stepInternal(frame, range, block);
}

@Specialization(guards = { "isIntegerFixnumRange(range)", "!isInteger(step)", "!isLong(step)", "wasProvided(step)" })
@Specialization(guards = {
"isIntegerFixnumRange(range)",
"!isInteger(step)",
"!isLong(step)",
"wasProvided(step)"
})
public Object stepInt(VirtualFrame frame, DynamicObject range, Object step, NotProvided block) {
return stepInternal(frame, range, step, null);
}
@@ -516,21 +526,38 @@ public RubyNode coerceToBoolean(RubyNode excludeEnd) {

@Specialization(guards = "rubyClass == rangeClass")
public DynamicObject intRange(DynamicObject rubyClass, int begin, int end, boolean excludeEnd) {
return Layouts.INTEGER_FIXNUM_RANGE.createIntegerFixnumRange(coreLibrary().getIntegerFixnumRangeFactory(), excludeEnd, begin, end);
return Layouts.INTEGER_FIXNUM_RANGE.createIntegerFixnumRange(
coreLibrary().getIntegerFixnumRangeFactory(),
excludeEnd,
begin,
end);
}

@Specialization(guards = { "rubyClass == rangeClass", "fitsIntoInteger(begin)", "fitsIntoInteger(end)" })
public DynamicObject longFittingIntRange(DynamicObject rubyClass, long begin, long end, boolean excludeEnd) {
return Layouts.INTEGER_FIXNUM_RANGE.createIntegerFixnumRange(coreLibrary().getIntegerFixnumRangeFactory(), excludeEnd, (int) begin, (int) end);
return Layouts.INTEGER_FIXNUM_RANGE.createIntegerFixnumRange(
coreLibrary().getIntegerFixnumRangeFactory(),
excludeEnd,
(int) begin,
(int) end);
}

@Specialization(guards = { "rubyClass == rangeClass", "!fitsIntoInteger(begin) || !fitsIntoInteger(end)" })
public DynamicObject longRange(DynamicObject rubyClass, long begin, long end, boolean excludeEnd) {
return Layouts.LONG_FIXNUM_RANGE.createLongFixnumRange(coreLibrary().getLongFixnumRangeFactory(), excludeEnd, begin, end);
return Layouts.LONG_FIXNUM_RANGE.createLongFixnumRange(
coreLibrary().getLongFixnumRangeFactory(),
excludeEnd,
begin,
end);
}

@Specialization(guards = { "rubyClass != rangeClass || (!isIntOrLong(begin) || !isIntOrLong(end))" })
public Object objectRange(VirtualFrame frame, DynamicObject rubyClass, Object begin, Object end, boolean excludeEnd) {
public Object objectRange(
VirtualFrame frame,
DynamicObject rubyClass,
Object begin,
Object end,
boolean excludeEnd) {
if (cmpNode == null) {
CompilerDirectives.transferToInterpreter();
cmpNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
Original file line number Diff line number Diff line change
@@ -362,7 +362,7 @@ public Object read(
}
}

@Specialization(guards = {"isRubySymbol(identifier)", "identifier == cachedIdentifier"})
@Specialization(guards = { "identifier == cachedIdentifier", "isRubySymbol(cachedIdentifier)" })
public Object read(
VirtualFrame frame,
TruffleObject receiver,
@@ -455,7 +455,7 @@ public Object write(
}
}

@Specialization(guards = {"isRubySymbol(identifier)", "identifier == cachedIdentifier"})
@Specialization(guards = { "identifier == cachedIdentifier", "isRubySymbol(cachedIdentifier)" })
public Object write(
VirtualFrame frame,
TruffleObject receiver,
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public String stringUncached(DynamicObject value) {
return value.toString();
}

@Specialization(guards = { "isRubySymbol(symbol)", "symbol == cachedSymbol" }, limit = "getLimit()")
@Specialization(guards = { "symbol == cachedSymbol", "isRubySymbol(cachedSymbol)" }, limit = "getLimit()")
public String symbolCached(DynamicObject symbol,
@Cached("symbol") DynamicObject cachedSymbol,
@Cached("symbolToString(symbol)") String convertedString) {
Original file line number Diff line number Diff line change
@@ -36,12 +36,16 @@ public abstract class GetConstantNode extends RubyNode {
private final RestartableReadConstantNode readConstantNode;
private @Child CallDispatchHeadNode constMissingNode;

public GetConstantNode(RubyContext context, SourceSection sourceSection, RestartableReadConstantNode readConstantNode) {
public GetConstantNode(
RubyContext context,
SourceSection sourceSection,
RestartableReadConstantNode readConstantNode) {
super(context, sourceSection);
this.readConstantNode = readConstantNode;
}

public abstract Object executeGetConstant(VirtualFrame frame, Object module, String name, RubyConstant constant);
public abstract Object executeGetConstant(
VirtualFrame frame, Object module, String name, RubyConstant constant);

@Specialization(guards = { "constant != null", "!constant.isAutoload()" })
protected Object getConstant(DynamicObject module, String name, RubyConstant constant) {
@@ -58,21 +62,27 @@ protected Object autoloadConstant(VirtualFrame frame, DynamicObject module, Stri

// The autoload constant must only be removed if everything succeeds.
// We remove it first to allow lookup to ignore it and add it back if there was a failure.
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(getContext(), this, name);
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(getContext(),
this,
name);
try {
requireNode.require(frame, path, callNode);
return readConstantNode.readConstant(frame, module, name);
} catch (RaiseException e) {
Layouts.MODULE.getFields(constant.getDeclaringModule()).setAutoloadConstant(getContext(), this, name, path);
Layouts.MODULE.getFields(constant.getDeclaringModule()).
setAutoloadConstant(getContext(), this, name, path);
throw e;
}
}

@Specialization(guards = {
"constant == null",
"guardName(name, cachedName, sameNameProfile)"
}, limit = "getCacheLimit()")
protected Object missingConstantCached(VirtualFrame frame, DynamicObject module, String name, Object constant,
@Specialization(
guards = { "constant == null", "guardName(name, cachedName, sameNameProfile)" },
limit = "getCacheLimit()")
protected Object missingConstantCached(
VirtualFrame frame,
DynamicObject module,
String name,
Object constant,
@Cached("name") String cachedName,
@Cached("isValidConstantName(name)") boolean isValidConstantName,
@Cached("getSymbol(name)") DynamicObject symbolName,
@@ -81,15 +91,22 @@ protected Object missingConstantCached(VirtualFrame frame, DynamicObject module,
}

@Specialization(guards = "constant == null")
protected Object missingConstantUncached(VirtualFrame frame, DynamicObject module, String name, Object constant) {
protected Object missingConstantUncached(
VirtualFrame frame, DynamicObject module, String name, Object constant) {
final boolean isValidConstantName = isValidConstantName(name);
return doMissingConstant(frame, module, name, isValidConstantName, getSymbol(name));
}

private Object doMissingConstant(VirtualFrame frame, DynamicObject module, String name, boolean isValidConstantName, DynamicObject symbolName) {
private Object doMissingConstant(
VirtualFrame frame,
DynamicObject module,
String name,
boolean isValidConstantName,
DynamicObject symbolName) {
if (!isValidConstantName) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreExceptions().nameError(String.format("wrong constant name %s", name), name, this));
throw new RaiseException(coreExceptions().
nameError(String.format("wrong constant name %s", name), name, this));
}

if (constMissingNode == null) {
@@ -117,7 +134,8 @@ protected CallDispatchHeadNode createConstMissingNode() {
}

protected boolean guardName(String name, String cachedName, ConditionProfile sameNameProfile) {
// This is likely as for literal constant lookup the name does not change and Symbols always return the same String.
// This is likely as for literal constant lookup the name does not change and Symbols
// always return the same String.
if (sameNameProfile.profile(name == cachedName)) {
return true;
} else {
Loading