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

Commits on Dec 18, 2015

  1. Copy the full SHA
    01e9508 View commit details
  2. [Truffle] Update Shape in MetaClassWithShapeCacheNode.

    * Also rename specializations properly.
    eregon committed Dec 18, 2015
    Copy the full SHA
    a483b40 View commit details
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/

package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.object.DynamicObject;

public abstract class ShapeCachingGuards {

public static boolean updateShape(DynamicObject object) {
CompilerDirectives.transferToInterpreter();
return object.updateShape();
}

}
Original file line number Diff line number Diff line change
@@ -10,20 +10,23 @@
package org.jruby.truffle.nodes.objects;

import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
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.nodes.RubyNode;
import org.jruby.truffle.nodes.ShapeCachingGuards;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

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

public MetaClassWithShapeCacheNode(RubyContext context, SourceSection sourceSection) {
@@ -33,41 +36,46 @@ public MetaClassWithShapeCacheNode(RubyContext context, SourceSection sourceSect
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(guards = "object.getShape() == cachedShape",
assumptions = "cachedShape.getValidAssumption()",
limit = "1")
protected DynamicObject cachedSingletonClass(DynamicObject object,
protected DynamicObject cachedMetaClass(DynamicObject object,
@Cached("object.getShape()") Shape cachedShape,
@Cached("getMetaClass(cachedShape)") DynamicObject metaClass) {
return metaClass;
}

@Specialization
protected DynamicObject singletonClass(DynamicObject object) {
@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);
}

Original file line number Diff line number Diff line change
@@ -9,15 +9,17 @@
*/
package org.jruby.truffle.nodes.objectstorage;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.*;

import org.jruby.truffle.nodes.ShapeCachingGuards;
import org.jruby.truffle.runtime.Options;

@ImportStatic(ShapeCachingGuards.class)
public abstract class ReadHeadObjectFieldNode extends Node {
private final Object defaultValue;
protected final Object name;
@@ -58,11 +60,6 @@ protected Object readObjectFieldUncached(DynamicObject receiver) {
return receiver.get(name, defaultValue);
}

protected boolean updateShape(DynamicObject object) {
CompilerDirectives.transferToInterpreter();
return object.updateShape();
}

protected int getCacheLimit() {
return Options.FIELD_LOOKUP_CACHE;
}
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@
*/
package org.jruby.truffle.nodes.objectstorage;

import org.jruby.truffle.nodes.ShapeCachingGuards;
import org.jruby.truffle.runtime.Options;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
@@ -25,6 +26,7 @@
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;

@ImportStatic(ShapeCachingGuards.class)
public abstract class WriteHeadObjectFieldNode extends Node {

protected static final int CACHE_LIMIT = Options.FIELD_LOOKUP_CACHE;
@@ -112,11 +114,6 @@ protected Location getNewLocation(Shape newShape) {
return newShape.getProperty(name).getLocation();
}

protected boolean updateShape(DynamicObject object) {
CompilerDirectives.transferToInterpreter();
return object.updateShape();
}

protected Assumption createAssumption() {
return Truffle.getRuntime().createAssumption("object location is valid");
}