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: 1710f02fa61d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 71599e9c53b5
Choose a head ref
  • 2 commits
  • 18 files changed
  • 1 contributor

Commits on Oct 7, 2015

  1. Copy the full SHA
    303c301 View commit details
  2. [Truffle] Pass the context explicitly for Module and Class methods r…

    …eading the context field directly.
    eregon committed Oct 7, 2015
    Copy the full SHA
    71599e9 View commit details
Showing with 197 additions and 195 deletions.
  1. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/constants/GetConstantNode.java
  2. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/constants/WriteConstantNode.java
  3. +17 −17 truffle/src/main/java/org/jruby/truffle/nodes/core/ClassNodes.java
  4. +7 −6 truffle/src/main/java/org/jruby/truffle/nodes/core/CoreMethodNodeManager.java
  5. +5 −5 truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  6. +24 −24 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  7. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/SetTopLevelBindingNode.java
  8. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/methods/AddMethodNode.java
  9. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/methods/AliasNode.java
  10. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/methods/UndefNode.java
  11. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/objects/DefineOrGetModuleNode.java
  12. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/objects/SingletonClassNode.java
  13. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/objects/WriteClassVariableNode.java
  14. +3 −3 truffle/src/main/java/org/jruby/truffle/runtime/ModuleOperations.java
  15. +71 −71 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  16. +53 −52 truffle/src/main/java/org/jruby/truffle/runtime/core/ModuleFields.java
  17. +2 −2 truffle/src/main/java/org/jruby/truffle/runtime/loader/FeatureLoader.java
  18. +1 −1 truffle/src/main/java/org/jruby/truffle/translator/TranslatorDriver.java
Original file line number Diff line number Diff line change
@@ -54,12 +54,12 @@ 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(this, name);
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(getContext(), this, name);
try {
requireNode.require(path);
return readConstantNode.readConstant(frame, module, name);
} catch (RaiseException e) {
Layouts.MODULE.getFields(constant.getDeclaringModule()).setAutoloadConstant(this, name, path);
Layouts.MODULE.getFields(constant.getDeclaringModule()).setAutoloadConstant(getContext(), this, name, path);
throw e;
}
}
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public Object execute(VirtualFrame frame) {

final DynamicObject module = (DynamicObject) receiverObject;

Layouts.MODULE.getFields(module).setConstant(this, name, rhsValue);
Layouts.MODULE.getFields(module).setConstant(getContext(), this, name, rhsValue);

return rhsValue;
}
34 changes: 17 additions & 17 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ClassNodes.java
Original file line number Diff line number Diff line change
@@ -61,10 +61,10 @@ public static DynamicObject createClassClass(RubyContext context) {
* This constructor supports initialization and solves boot-order problems and should not
* normally be used from outside this class.
*/
public static DynamicObject createBootClass(DynamicObject classClass, DynamicObject superclass, String name) {
public static DynamicObject createBootClass(RubyContext context, DynamicObject classClass, DynamicObject superclass, String name) {
assert RubyGuards.isRubyClass(classClass);
assert superclass == null || RubyGuards.isRubyClass(superclass);
final ModuleFields model = new ModuleFields(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(classClass)).getContext(), null, name);
final ModuleFields model = new ModuleFields(context, null, name);

final DynamicObject rubyClass = Layouts.CLASS.createClass(Layouts.CLASS.getInstanceFactory(classClass), model, false, null, null);
assert RubyGuards.isRubyClass(rubyClass) : classClass.getShape().getObjectType().getClass();
@@ -75,7 +75,7 @@ public static DynamicObject createBootClass(DynamicObject classClass, DynamicObj
if (model.lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(rubyClass).name = Layouts.MODULE.getFields(rubyClass).givenBaseName;
} else {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(model.lexicalParent, model.givenBaseName, null);
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
}

if (superclass != null) {
@@ -97,12 +97,12 @@ public static DynamicObject createSingletonClassOfObject(RubyContext context, Dy
// Allocator is null here, we cannot create instances of singleton classes.
assert RubyGuards.isRubyClass(superclass);
assert attached == null || RubyGuards.isRubyModule(attached);
return ensureSingletonConsistency(createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), null, superclass, name, true, attached));
return ensureSingletonConsistency(context, createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), null, superclass, name, true, attached));
}

public static DynamicObject createRubyClass(RubyContext context, DynamicObject lexicalParent, DynamicObject superclass, String name) {
final DynamicObject rubyClass = createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), lexicalParent, superclass, name, false, null);
ensureSingletonConsistency(rubyClass);
ensureSingletonConsistency(context, rubyClass);
return rubyClass;
}

@@ -118,7 +118,7 @@ public static DynamicObject createRubyClass(RubyContext context, DynamicObject c
if (model.lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(rubyClass).name = Layouts.MODULE.getFields(rubyClass).givenBaseName;
} else {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(model.lexicalParent, model.givenBaseName, null);
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
}

if (superclass != null) {
@@ -140,33 +140,33 @@ public static DynamicObject createRubyClass(RubyContext context, DynamicObject c
}


public static void initialize(DynamicObject rubyClass, DynamicObject superclass) {
public static void initialize(RubyContext context, DynamicObject rubyClass, DynamicObject superclass) {
assert RubyGuards.isRubyClass(superclass);

Layouts.MODULE.getFields(rubyClass).parentModule = Layouts.MODULE.getFields(superclass).start;
Layouts.MODULE.getFields(superclass).addDependent(rubyClass);

Layouts.MODULE.getFields(rubyClass).newVersion();
ensureSingletonConsistency(rubyClass);
ensureSingletonConsistency(context, rubyClass);

DynamicObjectFactory factory = Layouts.CLASS.getInstanceFactory(superclass);
factory = Layouts.BASIC_OBJECT.setLogicalClass(factory, rubyClass);
factory = Layouts.BASIC_OBJECT.setMetaClass(factory, rubyClass);
Layouts.CLASS.setInstanceFactoryUnsafe(rubyClass, factory);
}

public static DynamicObject ensureSingletonConsistency(DynamicObject rubyClass) {
createOneSingletonClass(rubyClass);
public static DynamicObject ensureSingletonConsistency(RubyContext context, DynamicObject rubyClass) {
createOneSingletonClass(context, rubyClass);
return rubyClass;
}

public static DynamicObject getSingletonClass(DynamicObject rubyClass) {
public static DynamicObject getSingletonClass(RubyContext context, DynamicObject rubyClass) {
// We also need to create the singleton class of a singleton class for proper lookup and consistency.
// See rb_singleton_class() documentation in MRI.
return ensureSingletonConsistency(createOneSingletonClass(rubyClass));
return ensureSingletonConsistency(context, createOneSingletonClass(context, rubyClass));
}

public static DynamicObject createOneSingletonClass(DynamicObject rubyClass) {
public static DynamicObject createOneSingletonClass(RubyContext context, DynamicObject rubyClass) {
CompilerAsserts.neverPartOfCompilation();

if (Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(rubyClass))) {
@@ -177,11 +177,11 @@ public static DynamicObject createOneSingletonClass(DynamicObject rubyClass) {
if (getSuperClass(rubyClass) == null) {
singletonSuperclass = Layouts.BASIC_OBJECT.getLogicalClass(rubyClass);
} else {
singletonSuperclass = createOneSingletonClass(getSuperClass(rubyClass));
singletonSuperclass = createOneSingletonClass(context, getSuperClass(rubyClass));
}

String name = String.format("#<Class:%s>", Layouts.MODULE.getFields(rubyClass).getName());
Layouts.BASIC_OBJECT.setMetaClass(rubyClass, ClassNodes.createRubyClass(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(rubyClass)).getContext(), Layouts.BASIC_OBJECT.getLogicalClass(rubyClass), null, singletonSuperclass, name, true, rubyClass));
Layouts.BASIC_OBJECT.setMetaClass(rubyClass, ClassNodes.createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(rubyClass), null, singletonSuperclass, name, true, rubyClass));

return Layouts.BASIC_OBJECT.getMetaClass(rubyClass);
}
@@ -286,7 +286,7 @@ private DynamicObject initializeGeneralWithoutBlock(VirtualFrame frame, DynamicO
assert RubyGuards.isRubyClass(rubyClass);
assert RubyGuards.isRubyClass(superclass);

ClassNodes.initialize(rubyClass, superclass);
ClassNodes.initialize(getContext(), rubyClass, superclass);
triggerInheritedHook(frame, rubyClass, superclass);

return rubyClass;
@@ -297,7 +297,7 @@ private DynamicObject initializeGeneralWithBlock(VirtualFrame frame, DynamicObje
assert RubyGuards.isRubyClass(superclass);
assert RubyGuards.isRubyProc(block);

ClassNodes.initialize(rubyClass, superclass);
ClassNodes.initialize(getContext(), rubyClass, superclass);
triggerInheritedHook(frame, rubyClass, superclass);
moduleInitialize(frame, rubyClass, block);

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.object.DynamicObject;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
@@ -116,16 +117,16 @@ private void addCoreMethod(MethodDetails methodDetails) {
final RubyRootNode rootNode = makeGenericMethod(context, methodDetails);

if (method.isModuleFunction()) {
addMethod(module, rootNode, names, Visibility.PRIVATE);
addMethod(getSingletonClass(module), rootNode, names, Visibility.PUBLIC);
addMethod(context, module, rootNode, names, Visibility.PRIVATE);
addMethod(context, getSingletonClass(module), rootNode, names, Visibility.PUBLIC);
} else if (method.onSingleton() || method.constructor()) {
addMethod(getSingletonClass(module), rootNode, names, visibility);
addMethod(context, getSingletonClass(module), rootNode, names, visibility);
} else {
addMethod(module, rootNode, names, visibility);
addMethod(context, module, rootNode, names, visibility);
}
}

private static void addMethod(DynamicObject module, RubyRootNode rootNode, List<String> names, final Visibility originalVisibility) {
private static void addMethod(RubyContext context, DynamicObject module, RubyRootNode rootNode, List<String> names, final Visibility originalVisibility) {
assert RubyGuards.isRubyModule(module);

for (String name : names) {
@@ -139,7 +140,7 @@ private static void addMethod(DynamicObject module, RubyRootNode rootNode, List<
final InternalMethod method = new InternalMethod(rootNodeCopy.getSharedMethodInfo(), name, module, visibility, false,
Truffle.getRuntime().createCallTarget(rootNodeCopy), null);

Layouts.MODULE.getFields(module).addMethod(null, method.withVisibility(visibility).withName(name));
Layouts.MODULE.getFields(module).addMethod(context, null, method.withVisibility(visibility).withName(name));
}
}

Original file line number Diff line number Diff line change
@@ -1322,7 +1322,7 @@ public DynamicObject methodsRegular(VirtualFrame frame, Object self, boolean reg
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(regular, MethodFilter.PUBLIC_PROTECTED).toArray();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(getContext(), regular, MethodFilter.PUBLIC_PROTECTED).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}

@@ -1379,7 +1379,7 @@ public DynamicObject privateMethods(VirtualFrame frame, Object self, boolean inc
DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PRIVATE).toArray();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(getContext(), includeAncestors, MethodFilter.PRIVATE).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}

@@ -1426,7 +1426,7 @@ public DynamicObject protectedMethods(VirtualFrame frame, Object self, boolean i
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PROTECTED).toArray();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(getContext(), includeAncestors, MethodFilter.PROTECTED).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}

@@ -1456,7 +1456,7 @@ public DynamicObject publicMethods(VirtualFrame frame, Object self, boolean incl
final DynamicObject metaClass = metaClassNode.executeMetaClass(frame, self);

CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(includeAncestors, MethodFilter.PUBLIC).toArray();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterMethodsOnObject(getContext(), includeAncestors, MethodFilter.PUBLIC).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}

@@ -1799,7 +1799,7 @@ public DynamicObject singletonMethods(VirtualFrame frame, Object self, boolean i
}

CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterSingletonMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
Object[] objects = Layouts.MODULE.getFields(metaClass).filterSingletonMethods(getContext(), includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}

48 changes: 24 additions & 24 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public static DynamicObject createRubyModule(RubyContext context, DynamicObject
if (lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(module).name = Layouts.MODULE.getFields(module).givenBaseName;
} else {
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(lexicalParent, name, currentNode);
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(context, lexicalParent, name, currentNode);
}
return module;
}
@@ -322,7 +322,7 @@ public RubyNode coerceOldNameToString(RubyNode oldName) {

@Specialization
public DynamicObject aliasMethod(DynamicObject module, String newName, String oldName) {
Layouts.MODULE.getFields(module).alias(this, newName, oldName);
Layouts.MODULE.getFields(module).alias(getContext(), this, newName, oldName);
return module;
}

@@ -365,7 +365,7 @@ public DynamicObject appendFeatures(DynamicObject features, DynamicObject target
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("append_features must be called only on modules", this));
}
Layouts.MODULE.getFields(target).include(this, features);
Layouts.MODULE.getFields(target).include(getContext(), this, features);
taintResultNode.maybeTaint(features, target);
return nil();
}
@@ -414,7 +414,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(sharedMethodInfo, accessorName, module, visibility, false, callTarget, null);

Layouts.MODULE.getFields(module).addMethod(this, method);
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method);
return nil();
}
}
@@ -557,7 +557,7 @@ public DynamicObject autoload(DynamicObject module, String name, DynamicObject f
return nil();
}

Layouts.MODULE.getFields(module).setAutoloadConstant(this, name, filename);
Layouts.MODULE.getFields(module).setAutoloadConstant(getContext(), this, name, filename);

return nil();
}
@@ -776,7 +776,7 @@ public RubyNode coerceToString(RubyNode name) {
public Object setClassVariable(DynamicObject module, String name, Object value) {
RubyContext.checkClassVariableName(getContext(), name, this);

ModuleOperations.setClassVariable(module, name, value, this);
ModuleOperations.setClassVariable(getContext(), module, name, value, this);

return value;
}
@@ -1007,7 +1007,7 @@ public Object setConstant(DynamicObject module, String name, Object value) {
throw new RaiseException(getContext().getCoreLibrary().nameError(String.format("wrong constant name %s", name), name, this));
}

Layouts.MODULE.getFields(module).setConstant(this, name, value);
Layouts.MODULE.getFields(module).setConstant(getContext(), this, name, value);
return value;
}

@@ -1067,7 +1067,7 @@ public DynamicObject defineMethodMethod(DynamicObject module, String name, Dynam
}
}

Layouts.MODULE.getFields(module).addMethod(this, method.withName(name));
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method.withName(name));
return getSymbol(name);
}

@@ -1105,7 +1105,7 @@ private DynamicObject addMethod(DynamicObject module, String name, InternalMetho
method = method.withVisibility(Visibility.PRIVATE);
}

Layouts.MODULE.getFields(module).addMethod(this, method);
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method);
return getSymbol(name);
}

@@ -1132,7 +1132,7 @@ public DynamicObject extendObject(DynamicObject module, DynamicObject object) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorWrongArgumentType(module, "Module", this));
}

Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).include(this, module);
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).include(getContext(), this, module);
return module;
}

@@ -1426,7 +1426,7 @@ public DynamicObject prependFeatures(DynamicObject features, DynamicObject targe
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("prepend_features must be called only on modules", this));
}
Layouts.MODULE.getFields(target).prepend(this, features);
Layouts.MODULE.getFields(target).prepend(getContext(), this, features);
taintResultNode.maybeTaint(features, target);
return nil();
}
@@ -1499,7 +1499,7 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
@Specialization
public DynamicObject protectedInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PROTECTED).toArray();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(getContext(), includeAncestors, MethodFilter.PROTECTED).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}
}
@@ -1548,7 +1548,7 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject privateInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PRIVATE).toArray();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(getContext(), includeAncestors, MethodFilter.PRIVATE).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}
}
@@ -1607,7 +1607,7 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject publicInstanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC).toArray();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(getContext(), includeAncestors, MethodFilter.PUBLIC).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}
}
@@ -1656,7 +1656,7 @@ public RubyNode coerceToBoolean(RubyNode includeAncestors) {
public DynamicObject instanceMethods(DynamicObject module, boolean includeAncestors) {
CompilerDirectives.transferToInterpreter();

Object[] objects = Layouts.MODULE.getFields(module).filterMethods(includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
Object[] objects = Layouts.MODULE.getFields(module).filterMethods(getContext(), includeAncestors, MethodFilter.PUBLIC_PROTECTED).toArray();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}
}
@@ -1706,7 +1706,7 @@ public PrivateConstantNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject privateConstant(VirtualFrame frame, DynamicObject module, Object[] args) {
for (Object arg : args) {
String name = nameToJavaStringNode.executeToJavaString(frame, arg);
Layouts.MODULE.getFields(module).changeConstantVisibility(this, name, true);
Layouts.MODULE.getFields(module).changeConstantVisibility(getContext(), this, name, true);
}
return module;
}
@@ -1726,7 +1726,7 @@ public PublicConstantNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject publicConstant(VirtualFrame frame, DynamicObject module, Object[] args) {
for (Object arg : args) {
String name = nameToJavaStringNode.executeToJavaString(frame, arg);
Layouts.MODULE.getFields(module).changeConstantVisibility(this, name, false);
Layouts.MODULE.getFields(module).changeConstantVisibility(getContext(), this, name, false);
}
return module;
}
@@ -1769,7 +1769,7 @@ public RubyNode coerceToString(RubyNode name) {
@Specialization
public Object removeClassVariableString(DynamicObject module, String name) {
RubyContext.checkClassVariableName(getContext(), name, this);
return Layouts.MODULE.getFields(module).removeClassVariable(this, name);
return Layouts.MODULE.getFields(module).removeClassVariable(getContext(), this, name);
}

}
@@ -1792,7 +1792,7 @@ public RubyNode coerceToString(RubyNode name) {

@Specialization
Object removeConstant(DynamicObject module, String name) {
RubyConstant oldConstant = Layouts.MODULE.getFields(module).removeConstant(this, name);
RubyConstant oldConstant = Layouts.MODULE.getFields(module).removeConstant(getContext(), this, name);
if (oldConstant == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().nameErrorConstantNotDefined(module, name, this));
@@ -1884,7 +1884,7 @@ private void undefMethod(VirtualFrame frame, DynamicObject module, String name)
final InternalMethod method = ModuleOperations.lookupMethod(module, name);

if (method != null) {
Layouts.MODULE.getFields(module).undefMethod(this, method);
Layouts.MODULE.getFields(module).undefMethod(getContext(), this, method);
methodUndefinedNode.call(frame, module, "method_undefined", null, getSymbol(name));
} else {
CompilerDirectives.transferToInterpreter();
@@ -1950,7 +1950,7 @@ public SetMethodVisibilityNode(RubyContext context, SourceSection sourceSection,
public DynamicObject setMethodVisibility(VirtualFrame frame, DynamicObject module, Object name) {
final String methodName = nameToJavaStringNode.executeToJavaString(frame, name);

final InternalMethod method = Layouts.MODULE.getFields(module).deepMethodSearch(methodName);
final InternalMethod method = Layouts.MODULE.getFields(module).deepMethodSearch(getContext(), methodName);

if (method == null) {
CompilerDirectives.transferToInterpreter();
@@ -1964,10 +1964,10 @@ public DynamicObject setMethodVisibility(VirtualFrame frame, DynamicObject modul
* to this module.
*/
if (visibility == Visibility.MODULE_FUNCTION) {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(getContext(), this, method.withVisibility(Visibility.PUBLIC));
} else {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(visibility));
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method.withVisibility(visibility));
}

return module;
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public SetTopLevelBindingNode(RubyContext context, SourceSection sourceSection)
@Override
public Object execute(VirtualFrame frame) {
final DynamicObject binding = BindingNodes.createBinding(getContext(), frame.materialize());
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).setConstant(this, "TOPLEVEL_BINDING", binding);
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).setConstant(getContext(), this, "TOPLEVEL_BINDING", binding);
return nil();
}

Original file line number Diff line number Diff line change
@@ -56,10 +56,10 @@ public DynamicObject execute(VirtualFrame frame) {
final InternalMethod method = methodObject.withDeclaringModule(module).withVisibility(visibility);

if (method.getVisibility() == Visibility.MODULE_FUNCTION) {
Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(this, method.withVisibility(Visibility.PUBLIC));
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method.withVisibility(Visibility.PRIVATE));
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(module)).addMethod(getContext(), this, method.withVisibility(Visibility.PUBLIC));
} else {
Layouts.MODULE.getFields(module).addMethod(this, method);
Layouts.MODULE.getFields(module).addMethod(getContext(), this, method);
}

return getSymbol(method.getName());
Original file line number Diff line number Diff line change
@@ -37,14 +37,14 @@ public AliasNode(RubyContext context, SourceSection sourceSection, String newNam

@Specialization(guards = "isRubyModule(module)")
public Object alias(DynamicObject module) {
Layouts.MODULE.getFields(module).alias(this, newName, oldName);
Layouts.MODULE.getFields(module).alias(getContext(), this, newName, oldName);
return module;
}

// TODO (eregon, 10 May 2015): we should only have the module case as the child should be the default definee
@Specialization(guards = "!isRubyModule(object)")
public Object alias(Object object) {
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).alias(this, newName, oldName);
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).alias(getContext(), this, newName, oldName);
return object;
}

Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public void executeVoid(VirtualFrame frame) {
throw new RuntimeException(e);
}

Layouts.MODULE.getFields(moduleObject).undefMethod(this, name);
Layouts.MODULE.getFields(moduleObject).undefMethod(getContext(), this, name);
}

@Override
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ protected RubyConstant lookupForExistingModule(DynamicObject lexicalParent) {
// We know that we're redefining this constant as we're defining a class/module with that name. We remove
// the constant here rather than just overwrite it in order to prevent autoload loops in either the require
// call or the recursive execute call.
Layouts.MODULE.getFields(lexicalParent).removeConstant(this, name);
Layouts.MODULE.getFields(lexicalParent).removeConstant(getContext(), this, name);

requireNode.require((DynamicObject) constant.getValue());

Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ protected DynamicObject singletonClassSymbol(DynamicObject value) {

@Specialization(guards = "isRubyClass(rubyClass)")
protected DynamicObject singletonClassClass(DynamicObject rubyClass) {
return ClassNodes.getSingletonClass(rubyClass);
return ClassNodes.getSingletonClass(getContext(), rubyClass);
}

@Specialization(guards = { "!isNil(object)", "!isRubyBignum(object)", "!isRubySymbol(object)", "!isRubyClass(object)" })
@@ -93,7 +93,7 @@ public DynamicObject getNormalObjectSingletonClass(DynamicObject object) {
CompilerAsserts.neverPartOfCompilation();

if (RubyGuards.isRubyClass(object)) { // For the direct caller
return ClassNodes.getSingletonClass(object);
return ClassNodes.getSingletonClass(getContext(), object);
}

if (Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(object))) {
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public Object execute(VirtualFrame frame) {

final DynamicObject module = ReadClassVariableNode.resolveTargetModule(lexicalScope);

ModuleOperations.setClassVariable(module, name, rhsValue, this);
ModuleOperations.setClassVariable(getContext(), module, name, rhsValue, this);

return rhsValue;
}
Original file line number Diff line number Diff line change
@@ -335,14 +335,14 @@ public Object apply(DynamicObject module) {
}

@TruffleBoundary
public static void setClassVariable(DynamicObject module, final String name, final Object value, final Node currentNode) {
public static void setClassVariable(final RubyContext context, DynamicObject module, final String name, final Object value, final Node currentNode) {
assert RubyGuards.isRubyModule(module);

DynamicObject found = classVariableLookup(module, new Function<DynamicObject, DynamicObject>() {
@Override
public DynamicObject apply(DynamicObject module) {
if (Layouts.MODULE.getFields(module).getClassVariables().containsKey(name)) {
Layouts.MODULE.getFields(module).setClassVariable(currentNode, name, value);
Layouts.MODULE.getFields(module).setClassVariable(context, currentNode, name, value);
return module;
} else {
return null;
@@ -352,7 +352,7 @@ public DynamicObject apply(DynamicObject module) {

if (found == null) {
// Not existing class variable - set in the current module
Layouts.MODULE.getFields(module).setClassVariable(currentNode, name, value);
Layouts.MODULE.getFields(module).setClassVariable(context, currentNode, name, value);
}
}

142 changes: 71 additions & 71 deletions truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java

Large diffs are not rendered by default.

105 changes: 53 additions & 52 deletions truffle/src/main/java/org/jruby/truffle/runtime/core/ModuleFields.java
Original file line number Diff line number Diff line change
@@ -90,10 +90,10 @@ public ModuleFields(RubyContext context, DynamicObject lexicalParent, String giv
start = new PrependMarker(this);
}

public void getAdoptedByLexicalParent(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(currentNode, name, rubyModuleObject, false);
Layouts.MODULE.getFields(lexicalParent).setConstantInternal(context, currentNode, name, rubyModuleObject, false);
Layouts.MODULE.getFields(lexicalParent).addLexicalDependent(rubyModuleObject);

if (this.name == null) {
@@ -103,23 +103,23 @@ public void getAdoptedByLexicalParent(DynamicObject lexicalParent, String name,

if (lexicalParent == objectClass) {
this.name = name;
updateAnonymousChildrenModules();
updateAnonymousChildrenModules(context);
} else if (Layouts.MODULE.getFields(lexicalParent).hasName()) {
this.name = Layouts.MODULE.getFields(lexicalParent).getName() + "::" + name;
updateAnonymousChildrenModules();
updateAnonymousChildrenModules(context);
}
// else: Our lexicalParent is also an anonymous module
// and will name us when it gets named via updateAnonymousChildrenModules()
}
}

public void updateAnonymousChildrenModules() {
public void updateAnonymousChildrenModules(RubyContext context) {
for (Map.Entry<String, RubyConstant> entry : constants.entrySet()) {
RubyConstant constant = entry.getValue();
if (RubyGuards.isRubyModule(constant.getValue())) {
DynamicObject module = (DynamicObject) constant.getValue();
if (!Layouts.MODULE.getFields(module).hasName()) {
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(rubyModuleObject, entry.getKey(), null);
Layouts.MODULE.getFields(module).getAdoptedByLexicalParent(context, rubyModuleObject, entry.getKey(), null);
}
}
}
@@ -146,10 +146,10 @@ public void initCopy(DynamicObject from) {
}

// TODO (eregon, 12 May 2015): ideally all callers would be nodes and check themselves.
public void checkFrozen(Node currentNode) {
if (getContext().getCoreLibrary() != null && verySlowIsFrozen(getContext(), rubyModuleObject)) {
public void checkFrozen(RubyContext context, Node currentNode) {
if (context.getCoreLibrary() != null && verySlowIsFrozen(context, rubyModuleObject)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().frozenError(Layouts.MODULE.getFields(getLogicalClass()).getName(), currentNode));
throw new RaiseException(context.getCoreLibrary().frozenError(Layouts.MODULE.getFields(getLogicalClass()).getName(), currentNode));
}
}

@@ -168,14 +168,14 @@ public void insertAfter(DynamicObject module) {
}

@CompilerDirectives.TruffleBoundary
public void include(Node currentNode, DynamicObject module) {
public void include(RubyContext context, Node currentNode, DynamicObject module) {
assert RubyGuards.isRubyModule(module);

checkFrozen(currentNode);
checkFrozen(context, currentNode);

// If the module we want to include already includes us, it is cyclic
if (ModuleOperations.includesModule(module, rubyModuleObject)) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("cyclic include detected", currentNode));
throw new RaiseException(context.getCoreLibrary().argumentError("cyclic include detected", currentNode));
}

// We need to include the module ancestors in reverse order for a given inclusionPoint
@@ -228,14 +228,14 @@ public boolean isIncludedModuleBeforeSuperClass(DynamicObject module) {
}

@CompilerDirectives.TruffleBoundary
public void prepend(Node currentNode, DynamicObject module) {
public void prepend(RubyContext context, Node currentNode, DynamicObject module) {
assert RubyGuards.isRubyModule(module);

checkFrozen(currentNode);
checkFrozen(context, currentNode);

// If the module we want to prepend already includes us, it is cyclic
if (ModuleOperations.includesModule(module, rubyModuleObject)) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("cyclic prepend detected", currentNode));
throw new RaiseException(context.getCoreLibrary().argumentError("cyclic prepend detected", currentNode));
}

ModuleChain mod = Layouts.MODULE.getFields(module).start;
@@ -258,8 +258,8 @@ public void prepend(Node currentNode, DynamicObject module) {
* Set the value of a constant, possibly redefining it.
*/
@CompilerDirectives.TruffleBoundary
public void setConstant(Node currentNode, String name, Object value) {
if (getContext().getCoreLibrary().isLoadingRubyCore()) {
public void setConstant(RubyContext context, Node currentNode, String name, Object value) {
if (context.getCoreLibrary().isLoadingRubyCore()) {
final RubyConstant currentConstant = constants.get(name);

if (currentConstant != null) {
@@ -268,20 +268,20 @@ public void setConstant(Node currentNode, String name, Object value) {
}

if (RubyGuards.isRubyModule(value)) {
Layouts.MODULE.getFields(((DynamicObject) value)).getAdoptedByLexicalParent(rubyModuleObject, name, currentNode);
Layouts.MODULE.getFields(((DynamicObject) value)).getAdoptedByLexicalParent(context, rubyModuleObject, name, currentNode);
} else {
setConstantInternal(currentNode, name, value, false);
setConstantInternal(context, currentNode, name, value, false);
}
}

@CompilerDirectives.TruffleBoundary
public void setAutoloadConstant(Node currentNode, String name, DynamicObject filename) {
public void setAutoloadConstant(RubyContext context, Node currentNode, String name, DynamicObject filename) {
assert RubyGuards.isRubyString(filename);
setConstantInternal(currentNode, name, filename, true);
setConstantInternal(context, currentNode, name, filename, true);
}

public void setConstantInternal(Node currentNode, String name, Object value, boolean autoload) {
checkFrozen(currentNode);
public void setConstantInternal(RubyContext context, Node currentNode, String name, Object value, boolean autoload) {
checkFrozen(context, currentNode);

RubyConstant previous = constants.get(name);
if (previous == null) {
@@ -296,23 +296,23 @@ public void setConstantInternal(Node currentNode, String name, Object value, boo
}

@CompilerDirectives.TruffleBoundary
public RubyConstant removeConstant(Node currentNode, String name) {
checkFrozen(currentNode);
public RubyConstant removeConstant(RubyContext context, Node currentNode, String name) {
checkFrozen(context, currentNode);
RubyConstant oldConstant = constants.remove(name);
newLexicalVersion();
return oldConstant;
}

@CompilerDirectives.TruffleBoundary
public void setClassVariable(Node currentNode, String variableName, Object value) {
checkFrozen(currentNode);
public void setClassVariable(RubyContext context, Node currentNode, String variableName, Object value) {
checkFrozen(context, currentNode);

classVariables.put(variableName, value);
}

@CompilerDirectives.TruffleBoundary
public Object removeClassVariable(Node currentNode, String name) {
checkFrozen(currentNode);
public Object removeClassVariable(RubyContext context, Node currentNode, String name) {
checkFrozen(context, currentNode);

final Object found = classVariables.remove(name);
if (found == null) {
@@ -323,18 +323,18 @@ public Object removeClassVariable(Node currentNode, String name) {
}

@CompilerDirectives.TruffleBoundary
public void addMethod(Node currentNode, InternalMethod method) {
public void addMethod(RubyContext context, Node currentNode, InternalMethod method) {
assert method != null;

if (getContext().getCoreLibrary().isLoadingRubyCore()) {
if (context.getCoreLibrary().isLoadingRubyCore()) {
final InternalMethod currentMethod = methods.get(method.getName());

if (currentMethod != null && currentMethod.getSharedMethodInfo().getSourceSection() instanceof CoreSourceSection) {
return;
}
}

checkFrozen(currentNode);
checkFrozen(context, currentNode);
methods.put(method.getName(), method.withDeclaringModule(rubyModuleObject));
newVersion();

@@ -350,26 +350,27 @@ public void removeMethod(String methodName) {
}

@CompilerDirectives.TruffleBoundary
public void undefMethod(Node currentNode, String methodName) {
public void undefMethod(RubyContext context, Node currentNode, String methodName) {
final InternalMethod method = ModuleOperations.lookupMethod(rubyModuleObject, methodName);
if (method == null) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorUndefinedMethod(methodName, rubyModuleObject, currentNode));
throw new RaiseException(context.getCoreLibrary().nameErrorUndefinedMethod(methodName, rubyModuleObject, currentNode));
} else {
undefMethod(currentNode, method);
undefMethod(context, currentNode, method);
}
}

@CompilerDirectives.TruffleBoundary
public void undefMethod(Node currentNode, InternalMethod method) {
addMethod(currentNode, method.undefined());
public void undefMethod(RubyContext context, Node currentNode, InternalMethod method) {
addMethod(context, currentNode, method.undefined());
}

/**
* Also searches on Object for modules.
* Used for alias_method, visibility changes, etc.
* @param context TODO
*/
@CompilerDirectives.TruffleBoundary
public InternalMethod deepMethodSearch(String name) {
public InternalMethod deepMethodSearch(RubyContext context, String name) {
InternalMethod method = ModuleOperations.lookupMethod(rubyModuleObject, name);
if (method != null && !method.isUndefined()) {
return method;
@@ -388,12 +389,12 @@ public InternalMethod deepMethodSearch(String name) {
}

@CompilerDirectives.TruffleBoundary
public void alias(Node currentNode, String newName, String oldName) {
InternalMethod method = deepMethodSearch(oldName);
public void alias(RubyContext context, Node currentNode, String newName, String oldName) {
InternalMethod method = deepMethodSearch(context, oldName);

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

InternalMethod aliasMethod = method.withName(newName);
@@ -402,12 +403,12 @@ public void alias(Node currentNode, String newName, String oldName) {
aliasMethod = aliasMethod.withVisibility(Visibility.PRIVATE);
}

addMethod(currentNode, aliasMethod);
addMethod(context, currentNode, aliasMethod);
}

@CompilerDirectives.TruffleBoundary
public void changeConstantVisibility(Node currentNode, String name, boolean isPrivate) {
checkFrozen(currentNode);
public void changeConstantVisibility(RubyContext context, Node currentNode, String name, boolean isPrivate) {
checkFrozen(context, currentNode);
RubyConstant rubyConstant = constants.get(name);

if (rubyConstant != null) {
@@ -550,43 +551,43 @@ public Iterator<DynamicObject> iterator() {
};
}

public Collection<DynamicObject> filterMethods(boolean includeAncestors, MethodFilter filter) {
public Collection<DynamicObject> filterMethods(RubyContext context, boolean includeAncestors, MethodFilter filter) {
final Map<String, InternalMethod> allMethods;
if (includeAncestors) {
allMethods = ModuleOperations.getAllMethods(rubyModuleObject);
} else {
allMethods = getMethods();
}
return filterMethods(allMethods, filter);
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterMethodsOnObject(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);
} else {
allMethods = ModuleOperations.getMethodsUntilLogicalClass(rubyModuleObject);
}
return filterMethods(allMethods, filter);
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterSingletonMethods(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);
} else {
allMethods = getMethods();
}
return filterMethods(allMethods, filter);
return filterMethods(context, allMethods, filter);
}

public Collection<DynamicObject> filterMethods(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<>();
for (InternalMethod method : methods.values()) {
if (filter.filter(method)) {
filtered.add(getContext().getSymbolTable().getSymbol(method.getName()));
filtered.add(context.getSymbolTable().getSymbol(method.getName()));
}
}

Original file line number Diff line number Diff line change
@@ -74,9 +74,9 @@ public boolean require(String feature, Node currentNode) throws IOException {
throw new RaiseException(context.getCoreLibrary().loadErrorCannotLoad(feature, currentNode));
} finally {
if (dataConstantBefore == null) {
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).removeConstant(currentNode, "DATA");
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).removeConstant(context, currentNode, "DATA");
} else {
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).setConstant(currentNode, "DATA", dataConstantBefore.getValue());
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).setConstant(context, currentNode, "DATA", dataConstantBefore.getValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ private RubyRootNode parse(Node currentNode, RubyContext context, Source source,
final Object data = getData(context);

if (data != null) {
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).setConstant(currentNode, "DATA", data);
Layouts.MODULE.getFields(context.getCoreLibrary().getObjectClass()).setConstant(context, currentNode, "DATA", data);
}

// Translate to Ruby Truffle nodes