Skip to content

Commit

Permalink
Showing 6 changed files with 41 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -19,16 +19,16 @@
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.array.ArrayUtils;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNode;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNodeGen;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.truffle.language.objects.MetaClassNodeGen;

public class CachedMethodMissingDispatchNode extends CachedDispatchNode {

private final DynamicObject expectedClass;
private final Assumption unmodifiedAssumption;
private final InternalMethod method;

@Child private MetaClassWithShapeCacheNode metaClassNode;
@Child private MetaClassNode metaClassNode;
@Child private DirectCallNode callNode;

public CachedMethodMissingDispatchNode(
@@ -43,7 +43,7 @@ public CachedMethodMissingDispatchNode(
this.expectedClass = expectedClass;
this.unmodifiedAssumption = Layouts.MODULE.getFields(expectedClass).getUnmodifiedAssumption();
this.method = method;
this.metaClassNode = MetaClassWithShapeCacheNodeGen.create(context, getSourceSection(), null);
this.metaClassNode = MetaClassNodeGen.create(context, getSourceSection(), null);
this.callNode = Truffle.getRuntime().createDirectCallNode(method.getCallTarget());

/*
Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNode;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNodeGen;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.truffle.language.objects.MetaClassNodeGen;

public class CachedReturnMissingDispatchNode extends CachedDispatchNode {

private final DynamicObject expectedClass;
private final Assumption unmodifiedAssumption;

@Child private MetaClassWithShapeCacheNode metaClassNode;
@Child private MetaClassNode metaClassNode;

public CachedReturnMissingDispatchNode(
RubyContext context,
@@ -35,7 +35,7 @@ public CachedReturnMissingDispatchNode(

this.expectedClass = expectedClass;
this.unmodifiedAssumption = Layouts.MODULE.getFields(expectedClass).getUnmodifiedAssumption();
this.metaClassNode = MetaClassWithShapeCacheNodeGen.create(context, getSourceSection(), null);
this.metaClassNode = MetaClassNodeGen.create(context, getSourceSection(), null);
}

@Override
Original file line number Diff line number Diff line change
@@ -30,11 +30,11 @@
})
public abstract class IsANode extends RubyNode {

@Child MetaClassWithShapeCacheNode metaClassNode;
@Child private MetaClassNode metaClassNode;

public IsANode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
metaClassNode = MetaClassWithShapeCacheNodeGen.create(context, sourceSection, null);
metaClassNode = MetaClassNodeGen.create(context, sourceSection, null);
}

public abstract boolean executeIsA(Object self, DynamicObject module);
Original file line number Diff line number Diff line change
@@ -9,17 +9,16 @@
*/
package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;

/**
* Reads the internal metaclass of an object.
*/
@NodeChild(value="object", type=RubyNode.class)
public abstract class MetaClassNode extends RubyNode {

@@ -30,33 +29,51 @@ public MetaClassNode(RubyContext context, SourceSection sourceSection) {
public abstract DynamicObject executeMetaClass(Object value);

@Specialization(guards = "value")
protected DynamicObject singletonClassTrue(boolean value) {
protected DynamicObject metaClassClassTrue(boolean value) {
return getContext().getCoreLibrary().getTrueClass();
}

@Specialization(guards = "!value")
protected DynamicObject singletonClassFalse(boolean value) {
protected DynamicObject metaClassClassFalse(boolean value) {
return getContext().getCoreLibrary().getFalseClass();
}

@Specialization
protected DynamicObject singletonClass(int value) {
protected DynamicObject metaClassInt(int value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
protected DynamicObject singletonClass(long value) {
protected DynamicObject metaClassLong(long value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
protected DynamicObject singletonClass(double value) {
protected DynamicObject metaClassDouble(double value) {
return getContext().getCoreLibrary().getFloatClass();
}

@Specialization
protected DynamicObject singletonClass(DynamicObject object) {
@Specialization(guards = "object.getShape() == cachedShape",
assumptions = "cachedShape.getValidAssumption()",
limit = "1")
protected DynamicObject cachedMetaClass(DynamicObject object,
@Cached("object.getShape()") Shape cachedShape,
@Cached("getMetaClass(cachedShape)") DynamicObject metaClass) {
return metaClass;
}

@Specialization(guards = "updateShape(object)")
protected DynamicObject updateShapeAndMetaClass(DynamicObject object) {
return executeMetaClass(object);
}

@Specialization(contains = { "cachedMetaClass", "updateShapeAndMetaClass" })
protected DynamicObject metaClass(DynamicObject object) {
return Layouts.BASIC_OBJECT.getMetaClass(object);
}

protected static DynamicObject getMetaClass(Shape shape) {
return Layouts.BASIC_OBJECT.getMetaClass(shape.getObjectType());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNode;
import org.jruby.truffle.language.objects.MetaClassWithShapeCacheNodeGen;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.truffle.language.objects.MetaClassNodeGen;

/**
* Caches {@link ModuleOperations#lookupSuperMethod}
@@ -34,11 +34,11 @@
@NodeChild("self")
public abstract class LookupSuperMethodNode extends RubyNode {

@Child MetaClassWithShapeCacheNode metaClassNode;
@Child private MetaClassNode metaClassNode;

public LookupSuperMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
metaClassNode = MetaClassWithShapeCacheNodeGen.create(context, sourceSection, null);
metaClassNode = MetaClassNodeGen.create(context, sourceSection, null);
}

public abstract InternalMethod executeLookupSuperMethod(VirtualFrame frame, Object self);

1 comment on commit 2663f15

@eregon
Copy link
Member

@eregon eregon commented on 2663f15 Feb 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose was to avoid N*N nodes for instance in the dispatch chain. But we probably want something more specialized like CheckMetaClassNode or so with a constant metaClass/shape anyway.

Sorry, something went wrong.

Please sign in to comment.