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

Commits on Mar 20, 2015

  1. [Truffle] Work towards making the RubyClass.allocator field final.

    * Last usage is initialize, but that is not trivial.
    eregon committed Mar 20, 2015
    Copy the full SHA
    c55817b View commit details
  2. [Truffle] Fix naming.

    eregon committed Mar 20, 2015
    Copy the full SHA
    d390326 View commit details
Original file line number Diff line number Diff line change
@@ -684,7 +684,7 @@ public ClassExecNode(ClassExecNode prev) {
yield = prev.yield;
}

public abstract Object executeClassEval(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block);
public abstract Object executeClassExec(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block);

@Specialization
public Object classExec(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block) {
@@ -1002,7 +1002,7 @@ void classEval(VirtualFrame frame, RubyModule module, RubyProc block) {
CompilerDirectives.transferToInterpreterAndInvalidate();
classExecNode = insert(ModuleNodesFactory.ClassExecNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{null,null,null}));
}
classExecNode.executeClassEval(frame, module, new Object[]{}, block);
classExecNode.executeClassExec(frame, module, new Object[]{}, block);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -62,8 +62,7 @@ public Object execute(VirtualFrame frame) {
RubyClass superClassObject = getRubySuperClass(frame, context);

if (constant == null) {
definingClass = new RubyClass(context, lexicalParent, superClassObject, name);
definingClass.setAllocator(superClassObject.getAllocator());
definingClass = new RubyClass(context, lexicalParent, superClassObject, name, superClassObject.getAllocator());
callInherited(frame, superClassObject, definingClass);
} else {
if (constant.getValue() instanceof RubyClass) {
Original file line number Diff line number Diff line change
@@ -154,17 +154,10 @@ public CoreLibrary(RubyContext context) {

// Create the cyclic classes and modules

classClass = new RubyClass(context, null, null, null, "Class", false, null);
classClass.setAllocator(new RubyClass.ClassAllocator());

basicObjectClass = RubyClass.createBootClass(context, classClass, "BasicObject");
basicObjectClass.setAllocator(new RubyBasicObject.BasicObjectAllocator());

objectClass = RubyClass.createBootClass(context, classClass, "Object");
objectClass.setAllocator(basicObjectClass.getAllocator());

moduleClass = new RubyClass(context, classClass, null, null, "Module", false, null);
moduleClass.setAllocator(new RubyModule.ModuleAllocator());
classClass = RubyClass.createBootClass(context, null, "Class", new RubyClass.ClassAllocator());
basicObjectClass = RubyClass.createBootClass(context, classClass, "BasicObject", new RubyBasicObject.BasicObjectAllocator());
objectClass = RubyClass.createBootClass(context, classClass, "Object", basicObjectClass.getAllocator());
moduleClass = RubyClass.createBootClass(context, classClass, "Module", new RubyModule.ModuleAllocator());

// Close the cycles
classClass.unsafeSetLogicalClass(classClass);
@@ -185,8 +178,7 @@ public CoreLibrary(RubyContext context) {
// Create Exception classes

// Exception
exceptionClass = defineClass("Exception");
exceptionClass.setAllocator(new RubyException.ExceptionAllocator());
exceptionClass = defineClass("Exception", new RubyException.ExceptionAllocator());

// EncodingError
encodingErrorClass = defineClass(exceptionClass, "EncodingError");
@@ -229,14 +221,14 @@ public CoreLibrary(RubyContext context) {
// StandardError > SystemCallError
systemCallErrorClass = defineClass(standardErrorClass, "SystemCallError");
errnoModule = defineModule("Errno");
new RubyClass(context, errnoModule, systemCallErrorClass, "EACCES");
edomClass = new RubyClass(context, errnoModule, systemCallErrorClass, "EDOM");
new RubyClass(context, errnoModule, systemCallErrorClass, "EEXIST");
enoentClass = new RubyClass(context, errnoModule, systemCallErrorClass, "ENOENT");
enotemptyClass = new RubyClass(context, errnoModule, systemCallErrorClass, "ENOTEMPTY");
new RubyClass(context, errnoModule, systemCallErrorClass, "EPERM");
new RubyClass(context, errnoModule, systemCallErrorClass, "EXDEV");
einvalClass = new RubyClass(context, errnoModule, systemCallErrorClass, "EINVAL");
defineClass(errnoModule, systemCallErrorClass, "EACCES");
edomClass = defineClass(errnoModule, systemCallErrorClass, "EDOM");
defineClass(errnoModule, systemCallErrorClass, "EEXIST");
enoentClass = defineClass(errnoModule, systemCallErrorClass, "ENOENT");
enotemptyClass = defineClass(errnoModule, systemCallErrorClass, "ENOTEMPTY");
defineClass(errnoModule, systemCallErrorClass, "EPERM");
defineClass(errnoModule, systemCallErrorClass, "EXDEV");
einvalClass = defineClass(errnoModule, systemCallErrorClass, "EINVAL");

// ScriptError
RubyClass scriptErrorClass = defineClass(exceptionClass, "ScriptError");
@@ -308,18 +300,17 @@ public CoreLibrary(RubyContext context) {

// The rest

encodingCompatibilityErrorClass = new RubyClass(context, encodingClass, standardErrorClass, "CompatibilityError");
encodingCompatibilityErrorClass = defineClass(encodingClass, standardErrorClass, "CompatibilityError");

encodingConverterClass = new RubyClass(context, encodingClass, objectClass, "Converter");
encodingConverterClass.setAllocator(new RubyEncodingConverter.EncodingConverterAllocator());
encodingConverterClass = defineClass(encodingClass, objectClass, "Converter", new RubyEncodingConverter.EncodingConverterAllocator());

truffleModule = defineModule("Truffle");
truffleDebugModule = defineModule(truffleModule, "Debug");
defineModule(truffleModule, "Primitive");

rubiniusModule = defineModule("Rubinius");
byteArrayClass = new RubyClass(context, rubiniusModule, objectClass, "ByteArray");
stringDataClass = new RubyClass(context, rubiniusModule, objectClass, "StringData");
byteArrayClass = defineClass(rubiniusModule, objectClass, "ByteArray");
stringDataClass = defineClass(rubiniusModule, objectClass, "StringData");

// Include the core modules

@@ -452,13 +443,19 @@ private RubyClass defineClass(String name, Allocator allocator) {
}

private RubyClass defineClass(RubyClass superclass, String name) {
return new RubyClass(context, objectClass, superclass, name);
return new RubyClass(context, objectClass, superclass, name, superclass.getAllocator());
}

private RubyClass defineClass(RubyClass superclass, String name, Allocator allocator) {
RubyClass rubyClass = new RubyClass(context, objectClass, superclass, name);
rubyClass.setAllocator(allocator);
return rubyClass;
return new RubyClass(context, objectClass, superclass, name, allocator);
}

private RubyClass defineClass(RubyModule lexicalParent, RubyClass superclass, String name) {
return new RubyClass(context, lexicalParent, superclass, name, superclass.getAllocator());
}

private RubyClass defineClass(RubyModule lexicalParent, RubyClass superclass, String name, Allocator allocator) {
return new RubyClass(context, lexicalParent, superclass, name, allocator);
}

private RubyModule defineModule(String name) {
23 changes: 10 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/runtime/core/RubyClass.java
Original file line number Diff line number Diff line change
@@ -39,33 +39,34 @@ public class RubyClass extends RubyModule {
* This constructor supports initialization and solves boot-order problems and should not
* normally be used from outside this class.
*/
public static RubyClass createBootClass(RubyContext context, RubyClass classClass, String name) {
return new RubyClass(context, classClass, null, null, name, false, null);
public static RubyClass createBootClass(RubyContext context, RubyClass classClass, String name, Allocator allocator) {
return new RubyClass(context, classClass, null, null, name, false, null, allocator);
}

public RubyClass(RubyContext context, RubyModule lexicalParent, RubyClass superclass, String name) {
this(context, superclass.getLogicalClass(), lexicalParent, superclass, name, false, null);
public RubyClass(RubyContext context, RubyModule lexicalParent, RubyClass superclass, String name, Allocator allocator) {
this(context, superclass.getLogicalClass(), lexicalParent, superclass, name, false, null, allocator);
// Always create a class singleton class for normal classes for consistency.
ensureSingletonConsistency();
}

protected static RubyClass createSingletonClassOfObject(RubyContext context, RubyClass superclass, RubyModule attached, String name) {
// 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 new RubyClass(context, superclass.getLogicalClass(), null, superclass, name, true, attached).ensureSingletonConsistency();
// Allocator is null here, we cannot create instances of singleton classes.
return new RubyClass(context, superclass.getLogicalClass(), null, superclass, name, true, attached, null).ensureSingletonConsistency();
}

protected RubyClass(RubyContext context, RubyClass classClass, RubyModule lexicalParent, RubyClass superclass, String name, boolean isSingleton, RubyModule attached) {
private RubyClass(RubyContext context, RubyClass classClass, RubyModule lexicalParent, RubyClass superclass, String name, boolean isSingleton, RubyModule attached, Allocator allocator) {
super(context, classClass, lexicalParent, name, null);

assert isSingleton || attached == null;

this.allocator = allocator;
this.isSingleton = isSingleton;
this.attached = attached;

if (superclass != null) {
unsafeSetSuperclass(superclass);
allocator = superclass.allocator;
}
}

@@ -75,10 +76,6 @@ public void initialize(RubyClass superclass) {
allocator = superclass.allocator;
}

public void setAllocator(Allocator allocator) {
this.allocator = allocator;
}

/**
* This method supports initialization and solves boot-order problems and should not normally be
* used.
@@ -129,7 +126,7 @@ private RubyClass createOneSingletonClass() {
}

metaClass = new RubyClass(getContext(),
getLogicalClass(), null, singletonSuperclass, String.format("#<Class:%s>", getName()), true, this);
getLogicalClass(), null, singletonSuperclass, String.format("#<Class:%s>", getName()), true, this, null);

return metaClass;
}
@@ -166,7 +163,7 @@ public static class ClassAllocator implements Allocator {

@Override
public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node currentNode) {
return new RubyClass(context, context.getCoreLibrary().getClassClass(), null, null, null, false, null);
return new RubyClass(context, context.getCoreLibrary().getClassClass(), null, null, null, false, null, null);
}

}