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

Commits on Aug 11, 2016

  1. [Truffle] More flexible regexp for Truffle version.

    * They do not have -SNAPSHOT appended, just the commit hash.
    eregon committed Aug 11, 2016
    Copy the full SHA
    7da5ee2 View commit details
  2. Copy the full SHA
    fc644c7 View commit details
  3. Copy the full SHA
    6ebc681 View commit details
  4. [Truffle] Set the proper instanceFactory when copying classes.

    * Always copy the superclass.
    eregon committed Aug 11, 2016
    Copy the full SHA
    44e131b View commit details
  5. Copy the full SHA
    542368f View commit details
  6. Copy the full SHA
    af436d6 View commit details
2 changes: 1 addition & 1 deletion tool/jruby_eclipse
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ home = Dir.home rescue "/home/#{`whoami`.chomp}"
M2REPO = "#{home}/.m2/repository"

TRUFFLE_VERSION = File.foreach("#{JRUBY}/truffle/pom.rb") { |line|
break $1 if /'truffle\.version' => '(\d+\.\d+|\h+-SNAPSHOT)'/ =~ line
break $1 if /'truffle\.version' => '((?:\d+\.\d+|\h+)(?:-SNAPSHOT)?)'/ =~ line
}

TRUFFLEJARS = %W[
2 changes: 1 addition & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ module Utilities

def self.truffle_version
File.foreach("#{JRUBY_DIR}/truffle/pom.rb") do |line|
if /'truffle\.version' => '(\d+\.\d+(?:-SNAPSHOT)?|\h+-SNAPSHOT)'/ =~ line
if /'truffle\.version' => '((?:\d+\.\d+|\h+)(?:-SNAPSHOT)?)'/ =~ line
break $1
end
end
24 changes: 16 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/core/klass/ClassNodes.java
Original file line number Diff line number Diff line change
@@ -168,30 +168,37 @@ public static DynamicObject createRubyClass(RubyContext context,
fields.newVersion();
}

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);
// Singleton classes cannot be instantiated
if (!isSingleton) {
setInstanceFactory(rubyClass, superclass);
}

return rubyClass;
}

@TruffleBoundary
public static void initialize(RubyContext context, DynamicObject rubyClass, DynamicObject superclass) {
assert RubyGuards.isRubyClass(superclass);
assert !Layouts.CLASS.getIsSingleton(rubyClass) : "Singleton classes can only be created internally";

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

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

DynamicObjectFactory factory = Layouts.CLASS.getInstanceFactory(superclass);
setInstanceFactory(rubyClass, superclass);

// superclass is set only here in initialize method to its final value
Layouts.CLASS.setSuperclass(rubyClass, superclass);
}

public static void setInstanceFactory(DynamicObject rubyClass, DynamicObject baseClass) {
assert !Layouts.CLASS.getIsSingleton(rubyClass) : "Singleton classes cannot be instantiated";
DynamicObjectFactory factory = Layouts.CLASS.getInstanceFactory(baseClass);
factory = Layouts.BASIC_OBJECT.setLogicalClass(factory, rubyClass);
factory = Layouts.BASIC_OBJECT.setMetaClass(factory, rubyClass);
Layouts.CLASS.setInstanceFactoryUnsafe(rubyClass, factory);
// superclass is set only here in initialize method to its final value
Layouts.CLASS.setSuperclass(rubyClass, superclass);
}

private static DynamicObject ensureItHasSingletonClassCreated(RubyContext context, DynamicObject rubyClass) {
@@ -387,7 +394,8 @@ protected int getCacheLimit() {
public abstract static class AllocateConstructorNode extends CoreMethodArrayArgumentsNode {

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
public DynamicObject allocate(DynamicObject classClass) {
assert classClass == coreLibrary().getClassClass() : "Subclasses of class Class are forbidden in Ruby";
return createRubyClass(getContext(), coreLibrary().getClassClass(), null, coreLibrary().getObjectClass(), null, false, null, false);
}

Original file line number Diff line number Diff line change
@@ -15,7 +15,9 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.utilities.CyclicAssumption;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
@@ -145,6 +147,10 @@ public void updateAnonymousChildrenModules(RubyContext context) {
}
}

private boolean hasPrependedModules() {
return start.getParentModule() != this;
}

@TruffleBoundary
public void initCopy(DynamicObject from) {
assert RubyGuards.isRubyModule(from);
@@ -155,7 +161,8 @@ public void initCopy(DynamicObject from) {
this.constants.putAll(fromFields.constants);
this.classVariables.putAll(fromFields.classVariables);

if (fromFields.start.getParentModule() != fromFields) {
if (fromFields.hasPrependedModules()) {
// Then the parent is the first in the prepend chain
this.parentModule = fromFields.start.getParentModule();
} else {
this.parentModule = fromFields.parentModule;
@@ -164,6 +171,15 @@ public void initCopy(DynamicObject from) {
for (DynamicObject ancestor : fromFields.parentAncestors()) {
Layouts.MODULE.getFields(ancestor).addDependent(rubyModuleObject);
}

if (Layouts.CLASS.isClass(rubyModuleObject)) {
// Singleton classes cannot be instantiated
if (!Layouts.CLASS.getIsSingleton(from)) {
ClassNodes.setInstanceFactory(rubyModuleObject, from);
}

Layouts.CLASS.setSuperclass(rubyModuleObject, Layouts.CLASS.getSuperclass(from));
}
}

// TODO (eregon, 12 May 2015): ideally all callers would be nodes and check themselves.
Original file line number Diff line number Diff line change
@@ -1180,7 +1180,6 @@ public Object initializeCopyClass(DynamicObject self, DynamicObject from,
assert Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(self));

Layouts.MODULE.getFields(selfMetaClass).initCopy(fromMetaClass); // copy class methods
Layouts.CLASS.setSuperclass(self, Layouts.CLASS.getSuperclass(from));

return nil();
}